79404315

Date: 2025-02-01 02:09:20
Score: 0.5
Natty:
Report link

Answering your question directly - Yes, you can. But...

So, TanStack Query was designed in mind that it first of all serves utilities for managing server state. So it has many of additional features like caching, revalidating, query keys managing and others. When using it like manager for local state, you need to keep in mind all of that, and not forgot to set all the flags. Also you will end up with some kind of overhead on every state change to reevaluate this and for storing all query object properties like isPending, isError. It is really heavy and useless when you just want to store one bool flag for example.

Traditional client-side state managers simply can serve that task better and with greater DX. They also helps you to organize it in small thunks or stores. Zustand comes with useful tools for shallow comparison for example.

I personally ended up with that combination: using TanStack Query for managing server states and one of light-weight client-side managers for some exclusive pieces of shared client-only states.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Vitaliy Spiridonov