Novelty Polygonal Mathematics

    react-use-persistent-state
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.3 • Public • Published

    A react hook that stores your states to LocalStorage. It uses the localforage module to get and set the value.

    Example:

    const TestComponent = () => {
      const defaultValue = 1;
      const [value, setValue, hydrated] = usePersistentState(
        "storageKey",
        defaultValue
      );
      return <div onClick={() => setValue(value + 1)}>{value}</div>;
    };
    

    The hydrated variable is to check whether the hook has retrieved the stored value from LocalStorage on initial mount.

    Keywords

    none

    Install

    npm i react-use-persistent-state

    DownloadsWeekly Downloads

    2

    Version

    1.0.3

    License

    none

    Unpacked Size

    5.38 kB

    Total Files

    5

    Last publish

    Collaborators

    • watchdict