#Persisting dropdown state across routes

1 messages · Page 1 of 1 (latest)

novel sandal
#

Hello all! Trying to wrap my head around the mental model with respect to state management in a remix app and could use some feedback.

If I have a dropdown as part of a side navigation that has its values provided via a loader on the root route, but then allow the current selection to be managed via the user on the client (react context is used for the selected state and the provider is wrapping at the layout component in the root), how do I ensure this selection is maintained on any route change?

Currently the context value is being reset on any route change. Would I need to use a cookie to persist the selection across route changes?

fast warren
#

Storing state in a cookie is a good option. I use createCookieSessionStorage from remix to securely store data for my sessions. Another good option is to store data in the browser's local storage.

novel sandal
#

If the selection also changes a route parameter, would one option be to pull the route parameter from the url in the loader (or even on the client) and then match the dropdown option to that?