T
TanStack4mo ago
quickest-silver

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
like-gold
like-gold4mo 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
like-gold
like-gold4mo ago
genetic-orange
genetic-orange4mo 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?