T
TanStack7mo ago
absent-sapphire

root.tsx vs main.tsx

How do I decide what to put in src/main.tsx vs src/routes/__root.tsx? I am using Zustand, TS Query and Router, and ShadCN. I don't know where I should setup Zustand and TS Query or where I should put my sidebar.
3 Replies
multiple-amethyst
multiple-amethyst7mo ago
Create your ts query and zustand providers and create them alongside the router in main or wherever you call createRouter Your sidebar id image goes in root or a layout route
multiple-amethyst
multiple-amethyst7mo ago
like-gold
like-gold7mo ago
the difference is basically: if you need access to things in the loader, you need to add it to the router context, and that happens in createRouter, which usually happens in main. So that's why the queryClient is created there. If you just need to create a context provider that's available globally, I'd put that in the root route

Did you find this page helpful?