# @yao-react/use-reduce-value

> React hook to reduce changed values.

Latest version **0.1.2** (published 2020-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @yao-react/use-reduce-value
pnpm add @yao-react/use-reduce-value
yarn add @yao-react/use-reduce-value
bun add @yao-react/use-reduce-value
```

## 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.1.2 |
| Published | 2020-10-24 |
| First published | 2020-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | zhaoyao91 |
| Maintainers | zhaoyao91 |
| Keywords | react, hook, reduce-value |

## Links

- npm: https://www.npmjs.com/package/@yao-react/use-reduce-value
- Repository: https://github.com/yao-react/use-reduce-value
- Homepage: https://github.com/yao-react/use-reduce-value#readme
- Issues: https://github.com/yao-react/use-reduce-value/issues
- npm.io page: https://npm.io/package/@yao-react/use-reduce-value

## Dependencies (1)

- [shallowequal](https://npm.io/package/shallowequal.md) ^1.1.0

## 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.1.2 (latest) — 2020-10-24
- 0.1.1 — 2020-10-24
- 0.1.0 — 2020-10-24

## README

# @yao-react/use-reduce-value

React hook to reduce changed values.

## Installation

```
npm install @yao-react/use-reduce-value
```

```
yarn add @yao-react/use-reduce-value
```

## Getting started

```tsx
export const Demo = () => {
  const [index, setIndex] = useState(0);
  const indexes = useReduceValue(
    (acc, a) => [...acc, a], // reducer
    [], // initAcc
    index // value
  );
  return (
    <div>
      <button onClick={() => setIndex(x => x + 1)}>inc index</button>
      <p>Indexes: {String(indexes)}</p>
    </div>
  );
};
```

## API

| name    | type               | required | description |
| ------- | ------------------ | -------- | ----------- |
| reducer | (acc, curr) => acc | true     |             |
| initAcc     | any                | true     |             |
| value   | any                | true     |             |
| deps    | any[]              | false    |             |

## More words

- only changed value will trigger reduce to produce new acc
- if you want to treat continuous same values as different values for this hook, you can wrap the value as `[value]`

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