# nostore

> Global state management based on React Hooks

Latest version **0.0.25** (published 2020-01-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install nostore
pnpm add nostore
yarn add nostore
bun add nostore
```

## 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.0.25 |
| Published | 2020-01-06 |
| First published | 2019-11-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | titian |
| Maintainers | titian |
| Keywords | react, state management, store, react hooks |

## Links

- npm: https://www.npmjs.com/package/nostore
- Repository: https://github.com/ti-tian/nostore
- Homepage: https://github.com/ti-tian/nostore#readme
- Issues: https://github.com/ti-tian/nostore/issues
- npm.io page: https://npm.io/package/nostore

## 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.0.25 (latest) — 2020-01-06
- 0.0.24 — 2020-01-06
- 0.0.23 — 2020-01-06
- 0.0.22 — 2019-12-25
- 0.0.21 — 2019-12-17
- 0.0.20 — 2019-12-17
- 0.0.19 — 2019-12-17
- 0.0.18 — 2019-11-29
- 0.0.17 — 2019-11-29
- 0.0.16 — 2019-11-19
- 0.0.15 — 2019-11-19
- 0.0.14 — 2019-11-15
- 0.0.13 — 2019-11-11
- 0.0.12 — 2019-11-11
- 0.0.11 — 2019-11-11
- … 10 more at https://npm.io/package/nostore/versions

## README

[简体中文](./README.zh-cn.md) | English

# nostore

> Global state management based on React Hooks

[![GitHub](https://img.shields.io/github/license/ti-tian/nostore.svg?logo=github)](https://github.com/ti-tian/nostore)
[![codecov](https://img.shields.io/codecov/c/github/ti-tian/nostore/master?logo=codecov)](https://codecov.io/gh/ti-tian/nostore)
[![npm version](https://img.shields.io/npm/v/nostore.svg?logo=npm)](https://www.npmjs.com/package/nostore)
[![npm downloads](https://img.shields.io/npm/dw/nostore.svg?logo=npm)](https://www.npmjs.com/package/nostore)
[![npm bundle size (minified)](https://img.shields.io/bundlephobia/min/nostore@latest.svg?logo=javascript)](https://bundlephobia.com/result?p=nostore@latest)
[![Build Status](https://api.travis-ci.org/ti-tian/nostore.svg?branch=master)](https://travis-ci.org/nostore)
![React](https://img.shields.io/npm/dependency-version/nostore/peer/react?logo=react)

## Features

- One API, Simple but efficient
- Strongly typed with Typescript
- React hooks style
- Minimum granularity update component

> It can be used as `useState` in the global context. Indeed affect the whole body!

## Install

```bash
$ yarn add nostore
# or
$ npm install nostore --save
```

## Try It Online

[![Edit react](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/clever-ardinghelli-9r77d)

## use

### create a store

```javascript
// store.js

import { createStore } from "nostore";

const useStore = createStore({ count: 1 });

export default useStore;

// action 
export function useDecrease() {
  const [, setStore] = useStore();
  return () => {
    setStore(prevStore => ({
      count: prevStore.count - 1
    }));
  };
}

// multiple actions
export function useAction() {
  const [store, setStore] = useStore();
  return {
    decrease() {
      setStore({
        count: store.count - 1
      });
    },
    // async action
    async increase() {
      await wait(2000);
      setStore(prevStore => ({
        count: prevStore.count + 1
      }));
    }
  };
}	
```

### use store

```javascript
// Increase.jsx

import useStore, { useAction } from "./store.js";

function Increase() {
  const [store] = useStore();
  const { increase } = useAction();
  return (
    <>
      <h1>{store.count}</h1>
      <button onClick={increase}>increase</button>
    </>
  );
}
```

```javascript
// Decrease.jsx

import useStore, { useDecrease } from "./store.js";

function Decrease() {
  const [store] = useStore();
  const decrease = useDecrease();
  return (
    <>
      <h1>{store.count}</h1>
      <button onClick={decrease} />
    </>
  );
}
```

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