nuclear-js icon indicating copy to clipboard operation
nuclear-js copied to clipboard

Syncing NuclearJS state with React Router Query Params

Open mindjuice opened this issue 10 years ago • 0 comments

Has anyone done any work to sync NuclearJS state to React Router query parameters?

I currently do router.transitionTo() with the new URL query params whenever an action changes some state that is associated with a query param. The way I currently did it though, I need to put all my related state in the same module, which is not great (pretty sure I can fix this though).

Going the other way, when the URL changes for any reason (e.g., user presses Back, or types in a new URL) I hook off of React Router's willTransitionTo() and fire an action to update the state from the current URL parameters. I have a check in there to avoid making any changes if the URL parameters match the current state so I don't get an infinite cycle of changes.

Has anyone done any work to use this sort of pattern (or similar) in a cleaner way?

mindjuice avatar Sep 14 '15 22:09 mindjuice