Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support changing the router inside a Redux reducer? #111

Open
thomasjm opened this issue May 10, 2023 · 0 comments
Open

Support changing the router inside a Redux reducer? #111

thomasjm opened this issue May 10, 2023 · 0 comments

Comments

@thomasjm
Copy link

In some of my Redux reducers I want to simultaneously change the search (i.e. by modifying state.router.location.search and some other state. Since this library advertises "100% one source of truth (store)" and "100% one-way data flow (only dispatch actions!)", I expected this to work.

If the history were like any other react-redux component, this change would propagate from the store and the browser URL would be updated. But instead, the browser URL doesn't change and this becomes out of sync with state.router.

I looked into this and found that the side-effectful calls to history.push etc. happen inside the router middleware. Thus, to do what I wanted I had to write my own middleware which dispatches router events, so they can cause the desired side effects in the router middleware.

Suggestion: instead, what if the router middleware also examined the state after calling next(action), and looked for any change to state.router? If one is found, then it can again do the necessary history calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant