T
TanStack13mo ago
correct-apricot

tanstack router, tanstack query with zustand?

is tanstack router and tanstack query recommended to be used with zustand?**
5 Replies
other-emerald
other-emerald13mo ago
I would say it depends on your use case, but they do compliment each other pretty well
harsh-harlequin
harsh-harlequin13mo 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.
harsh-harlequin
harsh-harlequin13mo 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.
correct-apricot
correct-apricotOP13mo ago
what about authentication? should i do that over zustand? like store wise
other-emerald
other-emerald13mo 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?