# react-native-sticky-state

> Custom hook to persist React Native state using AsyncStorage

Latest version **1.3.3** (published 2022-01-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-native-sticky-state
pnpm add react-native-sticky-state
yarn add react-native-sticky-state
bun add react-native-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.3.3 |
| Published | 2022-01-31 |
| First published | 2021-03-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | urvianoob |
| Maintainers | urvianoob |
| Keywords | react, react-native, react native, async storage, asyncstorage, storage, useState, persist state, persist storage, persistant storage, persistant state, useStickyState |

## Links

- npm: https://www.npmjs.com/package/react-native-sticky-state
- Repository: https://github.com/ncheungg/react-native-sticky-state
- Homepage: https://github.com/ncheungg/react-native-sticky-state#readme
- Issues: https://github.com/ncheungg/react-native-sticky-state/issues
- npm.io page: https://npm.io/package/react-native-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.3.3 (latest) — 2022-01-31
- 1.3.2 — 2022-01-28
- 1.3.1 — 2022-01-28
- 1.3.0 — 2022-01-28
- 1.2.0 — 2022-01-28
- 1.1.0 — 2022-01-28
- 1.0.4 — 2021-03-24
- 1.0.3 — 2021-03-24
- 1.0.2 — 2021-03-24
- 1.0.1 — 2021-03-24
- 1.0.0 — 2021-03-24

## README

# react-native-sticky-state

Custom hook to persist React Native state using [AsyncStorage](https://www.npmjs.com/package/@react-native-async-storage/async-storage)

If you're looking to persist React state, check out [use-sticky-state](https://www.npmjs.com/package/use-sticky-state)

## ⚙️ Installation

In your react-native project folder, run:

```bash
npm i react-native-sticky-state --save
```

## 💻 Example

```js
import useStickyState from "react-native-sticky-state";

const App = () => {
  const [count, setCount] = useStickyState(0, -1, "count");

  return (
    <View>
      <Button onPress={() => setCount(count + 1)}>
        <Text>Increment</Text>
      </Button>

      <Text>{count === -1 ? "loading..." : count}</Text>
    </View>
  );
};
```

## 📚 Usage

```js
const [state, setState] = useStickyState(defaultValue, loadingValue, storageKey);
```

| Property     | Description                                                                                                                            |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
| defaultValue | The default value used if storageKey was not previously set                                                                            |
| loadingValue | The value temporarily used while waiting for `useStickyState()` to asynchronously grab previous value, can be the same as defaultValue |
| storageKey   | Unique string key used to persist data, using [AsyncStorage](https://github.com/react-native-async-storage/async-storage) package      |

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