Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ravid7000/use-browser-storage
Use localStorage and sessionStorage inside react component
https://github.com/ravid7000/use-browser-storage
Last synced: 5 days ago
JSON representation
Use localStorage and sessionStorage inside react component
- Host: GitHub
- URL: https://github.com/ravid7000/use-browser-storage
- Owner: ravid7000
- Created: 2021-02-23T09:16:07.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-02-25T06:58:57.000Z (over 3 years ago)
- Last Synced: 2024-04-26T10:05:23.713Z (7 months ago)
- Language: TypeScript
- Size: 222 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# use-browser-storage
> React hook to use browser's storage. Currently supporting localStorage and sessionStorage.
[![NPM](https://img.shields.io/npm/v/use-browser-storage.svg)](https://www.npmjs.com/package/use-browser-storage) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
## Install
```bash
npm install --save use-browser-storage
```## Usage
```tsx
import * as React from 'react'import { useBrowserStorage } from 'use-browser-storage'
const Component = () => {
const { getItem, setItem, removeItem } = useBrowserStorage({ forceUpdate: true });React.useEffect(() => {
window.setTimeout(() => {
setItem('welcome', 'Hi Dev, welcome!')
}, 1000);
}, [])return (
{getItem('welcome')}
)
}
```## Options
| Option | Type | Default Value | Defination |
| :------------- |:----------------------------------- | :------------- | :--------- |
| type? | `localStorage` or `sessionStorage` | `localStorage` | Specify type of browser storage. |
| timestamp? | boolean | false | Store values with timestamp. |
| forceUpdate? | boolean | false | Update react component after calling setItem and removeItem |Note: `?` denotes optional property
## LicenseMIT © [ravid7000](https://github.com/ravid7000)