https://github.com/bdbch/react-basic-hooks
https://github.com/bdbch/react-basic-hooks
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/bdbch/react-basic-hooks
- Owner: bdbch
- License: mit
- Created: 2020-08-19T15:18:44.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-21T15:29:01.000Z (about 3 years ago)
- Last Synced: 2025-02-12T18:21:21.859Z (over 1 year ago)
- Language: TypeScript
- Size: 169 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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.