# @tarocch1/use-store

> A state manager for React Hooks.

Latest version **3.2.1** (published 2021-03-10) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @tarocch1/use-store
pnpm add @tarocch1/use-store
yarn add @tarocch1/use-store
bun add @tarocch1/use-store
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.2.1 |
| Published | 2021-03-10 |
| First published | 2021-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Tarocch1 |
| Maintainers | tarocch1 |

## Links

- npm: https://www.npmjs.com/package/@tarocch1/use-store
- Repository: https://github.com/Tarocch1/use-store
- Homepage: https://github.com/Tarocch1/use-store#readme
- Issues: https://github.com/Tarocch1/use-store/issues
- npm.io page: https://npm.io/package/@tarocch1/use-store

## Recent versions

- 3.2.1 (latest) — 2021-03-10
- 3.2.0 — 2021-03-10
- 3.1.0 — 2021-03-09
- 3.0.1 — 2021-03-08
- 3.0.0 — 2021-03-08

## README

# UseStore

一个基于 React Hooks 的状态管理工具。

[![npm](https://img.shields.io/npm/v/@tarocch1/use-store)](https://www.npmjs.com/package/@tarocch1/use-store)
[![npm bundle size](https://img.shields.io/bundlephobia/min/@tarocch1/use-store)](https://bundlephobia.com/result?p=@tarocch1/use-store)
[![GitHub](https://img.shields.io/github/license/tarocch1/use-store)](https://github.com/Tarocch1/use-store/blob/master/LICENSE)
![Test Workflow](https://github.com/Tarocch1/use-store/workflows/Test%20Workflow/badge.svg)

## Install

```bash
npm install @tarocch1/use-store
```

## Usage

```jsx
import { Provider, useStore, defineStore } from '@tarocch1/use-store';

const countStore = defineStore({
  state: {
    count: 0,
  },
  action: {
    plus: () => ({ getState, setState }) => {
      const { count } = getState('countStore');
      setState({ count: count + 1 });
    },
    plusAsync: () => async ({ getState, setState }) => {
      await new Promise(resolve => setTimeout(resolve, 1000));
      const { count } = getState('countStore');
      setState({ count: count + 1 });
    },
    plusSomething: num => ({ getState, setState }) => {
      const { count } = getState('countStore');
      setState({ count: count + num });
    },
  },
});

function Counter() {
  const [countState, countAction] = useStore('countStore');
  return (
    <>
      <p>Count: {countState.count}</p>
      <button onClick={countAction.plus}>+</button>
      <button onClick={countAction.plusAsync}>+ async</button>
      <button onClick={() => countAction.plusSomething(2)}>+2</button>
    </>
  );
}

ReactDOM.render(
  <Provider store={{ countStore }}>
    <Counter />
  </Provider>,
  container,
);
```

[![Edit use-store](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/use-store-bwmom?fontsize=14&hidenavigation=1&module=/src/App.js&theme=dark&file=/src/App.js)

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