1.0.1 • Published 5 years ago

usereducers v1.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

useReducers

A React Hook to combine multiple reducers (similar to Redux's combineReducers)

React Hooks is here and it's awesome. React have provided a useReducer function with Hooks to use Redux-style reducer logic with Hooks. However, Redux also has a convenient combineReducers function which provides a dispatch which sends each action through all reducers so that one action can impact many parts of the state tree.

useReducers is an implementation of this functionality using React Hooks and the useReducer hook.

Usage:

const TestComponent = () => {
  function reducer1() {console.log('reducer 1 fired!');}
  function reducer2() {console.log('reducer 2 fired!');}

  [store, dispatch] = useReducers(reducer1, reducer2);

  useEffect(dispatch({}), []);
  
  return (
    <div />
  );
}

Output:

reducer 1 fired!
reducer 2 fired!
1.0.1

5 years ago

1.0.0

5 years ago