Detuned Detuned - 28 days ago 18
React JSX Question

Should you dispatch or call next multiple times inside of a Redux middleware?

I'm curious, I've seen in middlewares, such as

redux-promise-middleware
where we want a single action to fire off multiple actions (e.g. REQUEST, SUCCESS, FAILURE). However, in the middleware, we're provided the
dispatch
to be able to
dispatch
these actions. Is there a reason for calling these additional actions with
next(action)
over the
dispatch(action)
?

Answer

If you dispatch an action then it will go through all of the middleware chain again. On the other hand next just sends it along to the next middleware in the chain or straight to the reducers if there aren't any more middlewares.

Comments