Better way to get theme?
Im accessing the theme cookie on
__root
during loader
, but every client-side navigation triggers it.
Any better approach to just do it one time ?4 Replies
dependent-tan•3w ago
Does this help? https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#key-options
Data Loading | TanStack Router React Docs
Data loading is a common concern for web applications and is related to routing. When loading a page for your app, it's ideal if all of the page's async requirements are fetched and fulfilled as early...
dependent-tan•3w ago
Especially this:

adverse-sapphire•3w ago
i use an inline script like this
https://github.com/dotnize/react-tanstarter/blob/2b19669206aa5a7b16a2520297c2051dc579f873/src/routes/__root.tsx#L66-L71
or with a custom theme provider: https://github.com/dotnize/react-tanstarter/blob/main/src/components/theme-provider.tsx#L94-L100
it's client-side and executes very early so there is no flash/FOUC
inland-turquoise•3w ago
you can use react query to cache the result in the loader or beforeLoad