Skip to content

grochadc/use-reducer-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

useReducerMiddleware

This is a custom hook that extends native react useReducer to take middleware as its third argument.

Usage

const middleware = [
  (store) => (next) => (action) => {
    //store is the tuple returned by useReducer
    const [state, dispatch] = store;

    //Do something when an action is dispatched
    console.log("Action dispatched ", action);

    //pass the action to the next middleware (action can be modified before passing it)
    return next(action);
  },
];
const { state, dispatch } = useReducerMiddleware(
  reducer,
  initialValues,
  middleware
);

The way middleware should be written in this package is similar to redux's own middleware implementation.

About

An extender useReducer react hook that accepts middleware

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published