# use-sticky-state

> Custom hook to persist React state

Latest version **1.0.3** (published 2022-02-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install use-sticky-state
pnpm add use-sticky-state
yarn add use-sticky-state
bun add use-sticky-state
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2022-02-04 |
| First published | 2022-01-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | urvianoob |
| Maintainers | urvianoob |
| Keywords | react, localstorage state, local storage react, storage, useState, persist state, persist storage, persistant storage, persistant state, useStickyState |

## Links

- npm: https://www.npmjs.com/package/use-sticky-state
- Repository: https://github.com/ncheungg/use-sticky-state
- Homepage: https://github.com/ncheungg/use-sticky-state#readme
- Issues: https://github.com/ncheungg/use-sticky-state/issues
- npm.io page: https://npm.io/package/use-sticky-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

- 1.0.3 (latest) — 2022-02-04
- 1.0.2 — 2022-01-31
- 1.0.1 — 2022-01-28

## README

# use-sticky-state

Custom hook to persist React state on browser

If you're looking to persist React Native state, check out [react-native-sticky-state](https://www.npmjs.com/package/react-native-sticky-state)

## ⚙️ Installation

In your React project folder, run:

```bash
npm i use-sticky-state --save
```

## 💻 Example

```js
import useStickyState from "use-sticky-state";

const App = () => {
  const [count, setCount] = useStickyState(0, "counter-key");

  return (
    <div>
      <button onClick={() => setCount(count + 1)}>Increment</button>

      <p>{count}</p>
    </div>
  );
};
```

## 📚 Usage

```js
const [state, setState] = useStickyState(defaultValue, storageKey);
```

| Property     | Description                                                                                                                                                    |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| defaultValue | The default value used if storageKey was not previously set                                                                                                    |
| storageKey   | Unique string key used to persist data, using your browser's built in [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) API |

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