@clutch-marketplace/use-persisted-state

0.0.1 • Public • Published

use-persisted-state

A custom React Hook that provides a multi-instance, multi-tab/browser shared and persistent state.

use-persisted-state is not a hook itself, but is a factory that accepts a storage storageKey and an optional storage provider (default = localStorage) and returns a hook that you can use as a direct replacement for useState.

Features

💾 Persists the state to localStorage

🖥 Syncs between tabs and/or browser windows

📑 Shares state w/multiple hooks on a page

The state is shared with any other hook using the same key, either on the same page, across tabs, or even browser windows.

For example, open two copies of your app in two tabs or even two windows. Any changes to state in one tab will be rendered on the other tab.

You can also close the browser and the next time you run your app, the state will be rendered as it was before you closed your browser.

Readme

Keywords

none

Package Sidebar

Install

npm i @clutch-marketplace/use-persisted-state

Weekly Downloads

1

Version

0.0.1

License

none

Unpacked Size

384 kB

Total Files

31

Last publish

Collaborators

  • clutch-bot