T
TanStack16mo ago
stormy-gold

tanstack router, tanstack query with zustand?

is tanstack router and tanstack query recommended to be used with zustand?**
5 Replies
deep-jade
deep-jade16mo ago
I would say it depends on your use case, but they do compliment each other pretty well
old-apricot
old-apricot16mo ago
Yes they can be used together. You'll need to evaluate what you are using them for though. - Router, ofc, would handle the actual application routing and search param management. - Query, is for async state management, like server calls. - Zustand would be for client state, i.e. user configuration, signup form steps, etc. Just, don't make the mistake of making a query using TanStack Query and then caching it in Zustand.
old-apricot
old-apricot16mo ago
Tkdodo has a good article on using Zustand, which you should check out. https://tkdodo.eu/blog/working-with-zustand
Working with Zustand
Let's dive into some tips for working with Zustand - one of my favourite client state management libraries in React.
stormy-gold
stormy-goldOP16mo ago
what about authentication? should i do that over zustand? like store wise
deep-jade
deep-jade16mo ago
Authenticated Routes | TanStack Router React Docs
Authentication is an extremely common requirement for web applications. In this guide, we'll walk through how to use TanStack Router to build protected routes, and how to redirect users to login if they try to access them. The route.beforeLoad Option

Did you find this page helpful?