Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leny/react-use-storage
React Hook to handle local and session storage
https://github.com/leny/react-use-storage
react react-hooks
Last synced: 4 months ago
JSON representation
React Hook to handle local and session storage
- Host: GitHub
- URL: https://github.com/leny/react-use-storage
- Owner: leny
- License: unlicense
- Created: 2019-03-03T13:19:45.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T03:15:42.000Z (almost 2 years ago)
- Last Synced: 2024-10-28T15:35:55.995Z (4 months ago)
- Topics: react, react-hooks
- Language: JavaScript
- Homepage:
- Size: 1.46 MB
- Stars: 19
- Watchers: 5
- Forks: 11
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-use-storage
> [React Hook](https://reactjs.org/docs/hooks-intro.html) to handle local and session storage
* * *
## Install
npm install --save react-use-storage
## Usage
See this hooks as a *useState* hooks that syncs with **local/session storage**.
> ☝️ **NOTE:** if the value of the key in the storage change from another portion of your code, the hook keep it in sync and re-render your component with the new value.
### LocalStorage
```javascript
import {useLocalStorage} from "react-use-storage";// ...
const [value, setValue, removeValue] = useLocalStorage("key", "default value");```
### SessionStorage
```javascript
import {useSessionStorage} from "react-use-storage";// ...
const [value, setValue, removeValue] = useSessionStorage("key", "default value");```
## License
[UNLICENSED (public domain)](./LICENSE)