# react-use-state-reducer

> Use fetch with hooks

Latest version **0.1.1** (published 2020-04-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-use-state-reducer
pnpm add react-use-state-reducer
yarn add react-use-state-reducer
bun add react-use-state-reducer
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2020-04-25 |
| First published | 2020-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Arthur Agombart |
| Maintainers | hollypony |
| Keywords | react, hook, state |

## Links

- npm: https://www.npmjs.com/package/react-use-state-reducer
- Repository: https://github.com/HollyPony/react-use-state-reducer
- Issues: https://github.com/HollyPony/react-use-state-reducer/issues
- npm.io page: https://npm.io/package/react-use-state-reducer

## 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.1 (latest) — 2020-04-25
- 0.1.0 — 2020-04-11

## README

# React-Use-State-Reducer

A hook to avoid multiple declaration of `const [xLoading, setXLoading] = useState(false)`

## Sample

`npm i react-use-state-reducer`

```js
import React from "react";
import useStateReducer from "react-use-state-reducer";

export default function App() {
  const [state, dispatch] = useStateReducer({
    init: true,
    fetch: false
  });

  React.useEffect(() => {
    // /!\ Don't do that at home !! `setTimeout` had issues with React/hooks : https://medium.com/javascript-in-plain-english/usetimeout-react-hook-3cc58b94af1f
    setTimeout(() => dispatch(false, "init"), 1000);
  }, [dispatch]);

  if (state["init"]) {
    return <span>Initializing</span>;
  }

  return (
    <div>
      <span>{state["fetch"] ? "fetching" : "fetched"}</span>
      <span>{state[undefined]}</span>
      <button onClick={() => dispatch(true, "fetch")}>Start fetch</button>
      <button onClick={() => dispatch(false, "fetch")}>Stop fetch</button>
    </div>
  );
}


ReactDOM.render(<App />, document.getElementById("root"));
```

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