# use-sync-set-state

> - This React Hook lets you store the state in localStorage and sync it in between tabs, automagically.

Latest version **0.1.0** (published 2020-07-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-sync-set-state
pnpm add use-sync-set-state
yarn add use-sync-set-state
bun add use-sync-set-state
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2020-07-26 |
| First published | 2020-07-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Aman Bhardwaj |
| Maintainers | inblack67 |
| Keywords | react, localStorage, useState, hook, sync |

## Links

- npm: https://www.npmjs.com/package/use-sync-set-state
- Repository: https://github.com/inblack67/use-sync-set-state
- Homepage: https://github.com/inblack67/use-sync-set-state/blob/master/README.md
- npm.io page: https://npm.io/package/use-sync-set-state

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2020-07-26

## README

# use-sync-set-state

- This React Hook lets you store the state in localStorage and sync it in between tabs, automagically.

- **use-sync-set-state** is a superset of useState i.e, you can always set the state explicitly or via callback function, your call.

- What's difference is that it stores the state in the localStorage and syncs it between tabs by listening to localStorage's storage event.

### Installation

```sh
yarn add use-sync-set-state
```
or

```sh
npm i use-sync-set-state

```

### Usage

```js
import useSyncSetState from 'use-sync-set-state';

const App = () => {

  React.useEffect(() => {
    setTheme('light');
  }, [])

  const [theme, setTheme] = useSyncSetState('theme', 'dark');

  return <React.Fragment>

  <p data-testid='theme'>{ theme }
  </p>

  // changes will be reflected in all the tabs, without reload.
  <button onClick={e => setTheme((current) => current === 'dark' ? 'light' : 'dark')}>toggle</button>

  <p data-testid='localstorage'>
    {localStorage.getItem('theme')}
  </p>
  
  </React.Fragment>
}
```

### Repository

[Explore](https://github.com/inblack67/use-sync-set-state)

### About The Author

[Website](https://inblack67.netlify.app)

[Github](https://github.com/inblack67)

---
_Source: https://npm.io/package/use-sync-set-state · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
