# reducer-kit

> 100 LOC type-safe react state management with use-reducer for component.

Latest version **1.0.1** (published 2022-07-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install reducer-kit
pnpm add reducer-kit
yarn add reducer-kit
bun add reducer-kit
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-07-29 |
| First published | 2022-07-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 3 |
| Unpacked size | 29.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | shejinxin |
| Maintainers | xcodebuild |

## Links

- npm: https://www.npmjs.com/package/reducer-kit
- npm.io page: https://npm.io/package/reducer-kit

## Dependencies (3)

- [immer](https://npm.io/package/immer.md) ^9.0.15
- [use-context-selector](https://npm.io/package/use-context-selector.md) ^1.4.1
- [@testing-library/react](https://npm.io/package/@testing-library/react.md) ^13.3.0

## Recent versions

- 1.0.1 (latest) — 2022-07-29
- 1.0.0 — 2022-07-29

## README

# reducer-kit

100 LOC type-safe react state management with use-reducer for component.

## Usage

```tsx
import React from "react";
import { render } from "react-dom";
import { Action, createKit, Dispatch, Selector } from "reducer-kit";

const CounterKit = createKit({
  initialState: {
    count: 0
  },
  reducers: {
    inc(state, action: Action<number>) {
      state.count += action.payload;
    }
  }
});

type CounterKitType = typeof CounterKit;

const inc = (dispatch: Dispatch<CounterKitType>) => {
  dispatch({
    type: "inc",
    payload: 1
  });
};

const selectCount: Selector<CounterKitType> = (state) => state.count;

const Counter: React.FC = () => {
  const count = CounterKit.useSelector(selectCount);
  const dispatch = CounterKit.useDispatch();

  return (
    <button className="button" onClick={() => inc(dispatch)}>
      CLICK {count}
    </button>
  );
};

const App: React.FC = () => {
  return (
    <CounterKit.Provider>
      <Counter />
    </CounterKit.Provider>
  );
};

render(<App />, document.body);
```

## Why reducer-kit

- Easy and lightweight, 100 LOC with `use-context-selector`、`immer`、and `useReducer`.
- Minimal re-render with `useSelector`.
- Type safe.
- For component with `Provider`.


## Examples

See demo in [CodeSandbox](https://codesandbox.io/s/reducer-kit-example-39o1w3?file=/src/index.tsx:0-954).

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