Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mdwahiduzzamanemon/-emon-browser_storage_hook_react
This is a React hook that allows you to use the browser storage API in a simple way. (npm i browser_storage_hook_react)
https://github.com/mdwahiduzzamanemon/-emon-browser_storage_hook_react
cookies localstorage sessionstorage
Last synced: 28 days ago
JSON representation
This is a React hook that allows you to use the browser storage API in a simple way. (npm i browser_storage_hook_react)
- Host: GitHub
- URL: https://github.com/mdwahiduzzamanemon/-emon-browser_storage_hook_react
- Owner: MdWahiduzzamanEmon
- Created: 2022-11-21T08:14:05.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-20T13:12:09.000Z (almost 2 years ago)
- Last Synced: 2024-12-15T05:26:54.074Z (about 2 months ago)
- Topics: cookies, localstorage, sessionstorage
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/browser_storage_hook_react
- Size: 209 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Browser Storage Hook React
This is a React hook that allows you to use the browser storage API in a simple way.
## Installation
Use the package manager [npm/yarn](https://www.npmjs.com/) to install the package.((please read the documentation first))
```bash
npm i browser_storage_hook_react
``````bash
yarn add browser_storage_hook_react
```https://user-images.githubusercontent.com/83487057/203020447-75919272-9e3d-4abd-afc9-cd3908d39a50.mov
## Importing
```
import { useLocalStorage, useSessionStorage, useCookie, setCookie, getCookie } from 'browser_storage_hook_react';```
## How to use it
### Local Storage
```
const [value, setValue] = useLocalStorage('key', 'defaultValue');```
### Session Storage```
const [value, setValue] = useSessionStorage('key', 'defaultValue');```
### Cookie
```
const [value, setValue] = useCookie('key', 'defaultValue', expiry);```
### Manually set and get cookie
```
const value = getCookie('key');
setCookie('key', 'value', expiry);```
## Local Storage and Session Storage
```
Here value is the value stored in the browser storage ,
and setValue is the function to set the value in the browser storage.```
## Cookie
```
Here value is the value stored in the cookie ,
and setCookie is the function to set the value in the cookie.```
| Name | Type | Description |
| ------------ | ------ | --------------------------------- |
| key | string | The key of the value to be stored |
| value | string | The value to be stored |
| defaultValue | string | The default value to be stored |
| expiry | number | The expiry time of the cookie |## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
## Author
-
[Md Wahiduzzaman Emon]
## Contributing
- Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
* Please make sure to update tests as appropriate.