Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/blenderskool/react-localstorage-hooks

🔄 A collection of React hooks for reactively managing localStorage.
https://github.com/blenderskool/react-localstorage-hooks

cross-tab hooks library localstorage react reactjs sync typescript

Last synced: 3 months ago
JSON representation

🔄 A collection of React hooks for reactively managing localStorage.

Awesome Lists containing this project

README

        



react-localstorage-hooks



A collection of React hooks for reactively managing localStorage.













### Installation


npm i react-localstorage-hooks

### Documentation
- [`useLocalStorageState`](./src/useLocalStorageState/): creates reactive state variables synced with localStorage.
- [`useLocalStorageReducer`](./src/useLocalStorageReducer/): similar to [`useReducer`](https://reactjs.org/docs/hooks-reference.html#usereducer) but abstracted on top of localStorage.
- [`useLocalStorageSelector`](./src/useLocalStorageSelector/): hook to select some data from localStorage that automatically updates when selected data changes.
- [`createLocalStorageDispatch`](./src/createLocalStorageDispatch/): creates a dispatch method that directly updates localStorage.

### Usage
- Make sure your project is using React 16.18.0 or above.

- Install the package using `npm` or `yarn`
```bash
npm i react-localstorage-hooks
```

- Import the hooks either using ES6 named imports:
```js
import { useLocalStorageState } from 'react-localstorage-hooks';
```
or importing each hook directly from `lib`:
```js
import useLocalStorageState from 'react-localstorage-hooks/lib/useLocalStorageState/useLocalStorageState';
```

### License
This package is licensed under [MIT](./LICENSE)