Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bdbch/react-localstorage
Simple React hook for localstorage access
https://github.com/bdbch/react-localstorage
Last synced: about 2 months ago
JSON representation
Simple React hook for localstorage access
- Host: GitHub
- URL: https://github.com/bdbch/react-localstorage
- Owner: bdbch
- License: mit
- Created: 2019-10-05T00:44:01.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-06T22:52:50.000Z (over 1 year ago)
- Last Synced: 2024-10-10T21:26:21.263Z (2 months ago)
- Language: TypeScript
- Size: 84 KB
- Stars: 12
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- fucking-awesome-react-hooks - `@d2k/react-localstorage`
- awesome-react-hooks-cn - `@d2k/react-localstorage`
- awesome-react-hooks - `@d2k/react-localstorage`
- awesome-react-hooks - `@d2k/react-localstorage`
README
# `@d2k/react-localstorage`
> React hooks for easy and simple localstorage access
> You'll need to install `react`, `react-dom`, etc at `^16.8.4`
## Install
```sh
npm i @d2k/react-localstorage --save
```## Usage
React Localstorage gives you simple hooks to work with your localstorage. Here is some example code:
```jsx
import React from 'react'
import useLocalStorage from '@d2k/react-localstorage'const App = () => {
const [firstName, setFirstName, removeFirstName] = useLocalStorage('firstName', 'John')
const [lastName, setLastName, removeLastName] = useLocalStorage('lastName', 'Doe')// You can update localStorage data via setFirstName('John') or removeFirstName()
return (
Demo
{ firstName && lastName && (
Hello {firstName} {lastName}
)}
)
}
```Use `.set` or `.remove` to update data from your component.
All storage updates will be automatically synced with all components using the same localStorage value key.