use-reducer-state
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

useReducer state

React useReducer with state getter

About

A simple React hook useReducer implementation that supports state getting. Instead of just receiving the state and dispatch results from the useReducer hook, you receive a third option for fetching the state.

Installation

Install by running npm install use-reducer-state --save-dev, and import it in your project for it to be bundled by whatever build system you're using.

Usage

Import useReducer just as you would from React:

import React from "react";
import { useReducer } from "use-reducer-state";

function initialStateGetter() {
    return {
        // ...
    };
}

function reducerFn(state, action) {
    switch (action.type) {
        // ...
    }
}

export function MyComponent() {
    const [state, dispatch, getState] = useReducer(reducerFn, initialStateGetter);
    // ...
}

Package Sidebar

Install

npm i use-reducer-state

Weekly Downloads

32

Version

0.1.0

License

MIT

Unpacked Size

5.09 kB

Total Files

7

Last publish

Collaborators

  • perrymitchell