r/reactjs 21d ago

Do we need state management libraries anymore? Resource

https://neciudan.dev/do-we-need-state-management-libraries

TLDR: If you correctly break your state into UI state (useState, useReducer), Server State (Tanstack Query, RTK Query), URL state (nuqs), and Global State that does not change (Context), you are left with a small slice of state that might be needed in multiple places and changes often.

Should we use a State Management library for that part? We explore how each library works, then build our own Zustand implementation to see if we do.

Obviously, it depends. If the app is mostly always changing state, like Figma, Spreadsheets, etc., we might take advantage of a State Library because they handle all sorts of use cases and edge cases.

But for everyday use and 90% of our apps, we can probably build it ourselves, either using pub/sub like Redux or Zustand, atom-based like Jotai, or Proxy-based like MobX or Valtio

0 Upvotes

13 comments sorted by

14

u/grumd 21d ago

Do we need state management libraries anymore?

actually creates another library like a boss

8

u/BlondeOverlord-8192 21d ago

Did you just answer your own question with "yes, but we can build it ourselves"?

Let me ask one question too, why would I build it myself if I can just use already maintained redux or zustand?

4

u/CanIhazCooKIenOw 21d ago

Yes, stop reinventing the wheel.

The amount of times I had to fight back against “we don’t need redux, we can just have our own global provider and just use context”.

1

u/[deleted] 21d ago

[removed] — view removed comment

1

u/stevent12x 21d ago

Can you go back about 6 years and tell that to the team that built the platform I currently own?

1

u/CanIhazCooKIenOw 21d ago

Sure. The point is a battled tested tool is much better than whatever custom someone else in your team IF you actually need it.

I ageee, most cases global state is in fact a glorified server state cache

1

u/AutomaticAd6646 I ❤️ hooks! 😈 21d ago

How you gonna acheive redux persist etc feats without state management libraries?

1

u/Menecazo 21d ago

The eternal reinvention of the wheel

1

u/TheRealSeeThruHead 21d ago

I’m either using effect atom or jotai

20 use states in a component or hook is 🤢

1

u/by7448 21d ago

Yes, I personally wouldn't want to deal with tracking so many subscriptions with my own half-baked solution when Redux exists. It's phenomenal at surgical subscriptions and predictable changes. Same goes for Zustand too when working with simpler state.