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
correct-apricot•7mo ago
can you be more specific please?
passive-yellowOP•7mo 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)
correct-apricot•7mo ago
in which way?
passive-yellowOP•7mo ago
Zustand
correct-apricot•7mo ago
couldnt those components just introspect the router state and react accordingly?
passive-yellowOP•7mo 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
correct-apricot•7mo 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 loaderpassive-yellowOP•7mo ago
Right - I use both because I need to listen to search param changes