DEV Community

Cover image for Do you need state management still ?
Konfy
Konfy

Posted on

Do you need state management still ?

When I started working on my hausapp one question tickles my interest. I used to have a state management in place as a statement just in case if I need anything to be driven far from what I was expecting out of it.

My app is simple

Like many developers, I initially added state management “just in case” my app grew beyond expectations. But as I built more, I started questioning that decision.

My app is simple:

  • Select your block
  • Upload a picture
  • Make sure maintenance is paid on time

I do plan to extend it later, but for now, the scope is limited. That’s where the dilemma begins.

Dilemma

We have global and local state management. A good developer keeps state close to the component housing. This is what I have learnt so far but sometime you need global state for this too.

For example:

When a user visits again, I want to remember their selected block.

When they navigate to other services (help, previous maintenance records), I need access to shared user data like haus number or name.

At this point, traditional solutions come to mind:

  • Redux
  • Jotai
  • Zustand

And yes, they would work.

I can do this via a state management, jotai might help or rather redux is there with me

But, lets pause for a second. Its a small component which makes calls and retrieves the data from the backend and displays it. Do you agree ?

For this, I don't need lots of boilerplate or no state management at all right ?

Hello tanstack

Enter TanStack Query

This is where TanStack Query clicked for me.

Most of what I was trying to “manage” was actually server state:

  • Fetching user data
  • Caching responses
  • Keeping data fresh
  • Avoiding unnecessary refetches

TanStack Query already solves all of this:

  • Built-in caching
  • Stale-while-revalidate
  • Automatic background refetching

And for the remaining lightweight client state,
TanStack Store is more than enough for my use case—without the mental overhead of a full state management library.

So, its a win-win for me using it and move on with my backend prisma schemas.

Just my thoughts shared over here. what do you think?

Top comments (0)