Answer the question
In order to leave comments, you need to log in
Is it correct in Redux ideology to dispatch an action after the fact?
Good day.
There is a router (react-router). I integrated routing with Redux, and it turns out that in order not to break the work of react-router, I have to dispatch the ROUTE_CHANGE action after the route has changed. In code, I implement this by listening for browser history changes. Actually, the already existing react-router-redux works in the same way, only it is less flexible and does not allow passing parameters to state.
Further, since the ROUTE_CHANGE dispatcher is implemented after the fact, it is very convenient to use native react-router tools, in particular, the Redirect component in order to make redirects in the right places, instead of dispatch(push('/route')).
Actually, the essence of the question: is it permissible? The sequence of events is as follows: route change > dispatch > state update. As far as I know, redux assumes a slightly different order: dispatch > route change in response to dispatch > state update.
Answer the question
In order to leave comments, you need to log in
And why do you need such integration of routing with Redux ? I mean, many people shove everything into the store, without understanding why.
It is not clear why in this scheme dispatch > update state , why not use it since the project uses react-router-redux ?
Directly Redux assumes only dispatch > update state . The rest is middleware and side effects. We didn't use react-router-redux
at all in the last two projects .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question