JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10988
  • Score
    100M100P100Q5603F
  • License MIT

React hook for managing effects from reducers.

Package Exports

  • react-use-bireducer

Readme

🔀 React use bireducer tests codecov npm

React hook for managing effects from reducers.

Installation

yarn add react-use-bireducer
# or
npm install react-use-bireducer

Usage

The API is very close to useReducer, except that:

  • The state reducer returns [State, Effect[]] instead of State
  • You need to pass an effect reducer
import {useBireducer} from "react-use-bireducer";

declare function stateReducer(state: State, action: Action): [State, Effect[]];
declare function effectReducer(effect: Effect): EffectCleanup | void;

const [state, dispatch] = useBireducer(stateReducer, effectReducer, defaultState);

See a complete example on CodeSandbox.

Development

Development environment is managed by Nix. First you need to install it:

curl -L https://nixos.org/nix/install | sh

Then you can start your development environment by spawning a Nix shell:

nix-shell

Now you should be able to clone the repo and install Node.js dependencies:

git clone https://github.com/soywod/react-use-bireducer.git
cd react-use-bireducer
yarn

You can leave the development environment either by killing your terminal or by entering the command exit.

Tests

Tests are handled by Jest (.test files) and React Testing Library (.spec files).

yarn test

Sponsoring

github paypal ko-fi buy-me-a-coffee liberapay