npm i react-localstorage-hooks
useLocalStorageState: creates reactive state variables synced with localStorage.useLocalStorageReducer: similar touseReducerbut abstracted on top of localStorage.useLocalStorageSelector: hook to select some data from localStorage that automatically updates when selected data changes.createLocalStorageDispatch: creates a dispatch method that directly updates localStorage.
-
Make sure your project is using React 16.18.0 or above.
-
Install the package using
npmoryarnnpm i react-localstorage-hooks
-
Import the hooks either using ES6 named imports:
import { useLocalStorageState } from 'react-localstorage-hooks';
or importing each hook directly from
lib:import useLocalStorageState from 'react-localstorage-hooks/lib/useLocalStorageState/useLocalStorageState';
This package is licensed under MIT