T
TanStack7mo ago
passive-yellow

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

Did you find this page helpful?