Managing some global state from route callbacks?
Is it a bad idea to manage some global state within a routes callbacks? Reason I’m second guessed by this (even though it does what I want) is that loaders can be re-run anytime… so it could cause potential state inconsistencies?
8 Replies
stormy-gold•10mo ago
can you be more specific please?
adverse-sapphireOP•10mo ago
Sure - I have 2 global sidebars (left and right) that depending on route need to change state. The left sidebar controls a bit more state (such as setting a component view)
stormy-gold•10mo ago
in which way?
adverse-sapphireOP•10mo ago
Zustand
stormy-gold•10mo ago
couldnt those components just introspect the router state and react accordingly?
adverse-sapphireOP•10mo ago
Of course - but thought why not do it on the router level. My issue is that some links needs to have preloading off because some of these state changes are made within a loader and a preload always calls the loader
So this is why I’m second guessing that this might be a bad idea
stormy-gold•10mo ago
you get a
preload flag in the loader to know whether you are preloading or not
i would rather use the onEnter etc methods
not the loaderadverse-sapphireOP•10mo ago
Right - I use both because I need to listen to search param changes