How to use the @rehooks/local-storage function in @rehooks/local-storage

To help you get started, we’ve selected a few @rehooks/local-storage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brentvollebregt / who-is-on-my-network / webapp / src / pages / Home / ChartWrapper.tsx View on Github external
const ChartWrapper: React.FC = ({ entityType, selectedIds }) => {
  const [storedStartAndEndDates, setStoredStartAndEndDates] = useLocalStorage<
    [string, string]
  >("home_selectedDates", [defaultStartDate.toISO(), defaultEndDate.toISO()]);

  const getStartDate = () =>
    storedStartAndEndDates === null
      ? defaultStartDate
      : DateTime.fromISO(storedStartAndEndDates[0]);
  const getEndDate = () =>
    storedStartAndEndDates === null
      ? defaultEndDate
      : DateTime.fromISO(storedStartAndEndDates[1]);

  const getStartAndEndDates = (): [DateTime, DateTime] => [
    getStartDate(),
    getEndDate()
  ];
github brentvollebregt / who-is-on-my-network / webapp / src / hooks / useStoredDatePair.ts View on Github external
const useStoredDatePair = (
  storageKey: string,
  defaultStartDate: DateTime,
  defaultEndDate: DateTime
) => {
  const [storedStartAndEndDates, setStoredStartAndEndDates] = useLocalStorage<[string, string]>(
    storageKey + "_selectedDates",
    [defaultStartDate.toISO(), defaultEndDate.toISO()]
  );

  const getStartDate = () =>
    storedStartAndEndDates === null
      ? defaultStartDate
      : DateTime.fromISO(storedStartAndEndDates[0]);

  const getEndDate = () =>
    storedStartAndEndDates === null ? defaultEndDate : DateTime.fromISO(storedStartAndEndDates[1]);

  const getStartAndEndDates = (): [DateTime, DateTime] => [getStartDate(), getEndDate()];

  const setStartAndEndDates = (startDate: DateTime, endDate: DateTime) => {
    setStoredStartAndEndDates([startDate.toISO(), endDate.toISO()]);

@rehooks/local-storage

React hook for local-storage

MIT
Latest version published 1 year ago

Package Health Score

60 / 100
Full package analysis