#Best way to manage UI state (theme, sidebar) in React Router Framework Mode

1 messages · Page 1 of 1 (latest)

fresh elk
#

In React Router Framework Mode, what’s the recommended way to manage UI state like:

  • Theme (light/dark mode)
  • Sidebar toggle
  • Drawer open/close

Especially when this state needs to be accessed and updated from multiple components across different routes?

I was confused while reading the documentation about which one I should use.

zealous oracle
#

hello there, usually if it is client side state like
Sidebar/Drawer toggling I'd suggest using something like Context or Zustand,

Otherwise, cookies could be another option for things like Theme, data that should be accessible on server rendering, cool thing about cookies is that you can get/set them on on loaders and actions, then return their values and make it accessible on client UI

Summary

  • Client side only: React Context, Zustand, or similar
  • Otherwise, use the server APIs, cookies, URL search params, etc...
#

for example, I'd use URL serach params for pagination and filters

fresh elk
#

thank you @zealous oracle !

finite wedge
#

I was using zustand for client side state, but recently discovered Jotai and much prefer it. I only have a small amount of state to keep and it is dead simple. I love how it automatically reflects the new state on all open windows/tabs.