Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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)