dispatch action in side effect hooks
djkirby opened this issue · 4 comments
Adding side-effects with event hooks
...
redux-pack lets you do that through event hooks functions. These are functions attached to the meta attribute of the original action. They are called with two parameters:
- the matching step payload (varies based on the step, details below)
- the getState function
It would be nice to be able to dispatch an action inside the side effect handlers. Is there a good reason for not passing dispatch
along with getState
here? Thanks.
It seems like it'd be a perfect place to set up dispatches. You'd basically get all the functionality of redux-loop
, but while still keeping the reducers "dumb" and keeping all multi-step logic in the action creators.
Any thoughts on this @lelandrichardson? I would open a PR if desired. Or I'd be interested in how you would handle a case where you want to dispatch an action as a result of another action -- it seems this doesn't fully replace what thunk would give you.
Wouldn't this seemingly break the point of the library. One of the major advantages is to avoid dispatching multiple actions from one actionCreator. This is because that breaks the cycle of component->action->reducer
, changing it to component->action->( 0-infinity more actions with difficult to track side effects )->( reduce for each action in order of actions )
.
Doing this would cause the same issue of side effects that sagas/thunk create, and also makes it easier to introduce race conditions between reducing each action if multiple of them are async.
I ended up just using middleware for these cases.