DEV Community

Cover image for What's your go to state management library these days?
Nick Taylor
Nick Taylor Subscriber

Posted on

9

What's your go to state management library these days?

We use Preact at Forem, the software that powers dev.to, but we do not use a state management library, just good old component state.

The last state management library I used was Redux back in Fall of 2018. If you require a state management library for your project, I'm curious which one do you use? Zustand, Redux, Recoil etc. or is it something more like React Query these days?

Also, what do you like/dislike about the state management library you use?

Go!

Photo by Alfons Morales on Unsplash

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (26)

Collapse
 
danieltott profile image
Dan Ott

I am a HUGE believer in react-query - it handles 99% of the nonsense we used to try to pump into redux. So - for request data, react-query for sure.

After that, it would take a lot for me to use something other than useState or useReducer for state, and useContext if I really need to.

I try to keep state as local as it can be, and that serves me very well most of the time.

Collapse
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

According to your comment and if I did not get you wrong... You should learn about Reducer Design Pattern which is just what Redux does strictly, so you can understand why it works this way. Also I can understand that Redux works with functional programming paradigm and can be a hard pill to swallow for people not used to it.
The only thing I can say in counter of Redux from an engineering point of view is that it could be less verbose tbh.

Trying to handle a supposedly unified global state as local state is just counter productive and goes against the pattern you're using. So either you didn't understand how it works and why or you understand it but you can't discern whether to use it or not.
There's no tech, design pattern, paradigm or a single thing to rule them all, each tool must be used when it covers the needs.

Also I must add to this comment a very important statement You might not need redux , and you can read the article from one of the team members that developed Redux itself. This can be applied to any of these libs to solve state management.

Things need to be analysed before applying them, otherwise science is left aside and we only obtain the technical part, which is precisely the one that must apply the results of science-based engineering which results in a blind following of things that people involved don't even understand.

Collapse
 
markerikson profile image
Mark Erikson • Edited

FWIW, I did a rough estimate of React ecosystem "state management market share" a few months ago, and this is what I came up with:

  • Redux: 45-50%
  • Apollo: 15%
  • XState: 8%
  • MobX: 7%
  • Redux Toolkit: 4.5% (overlaps with Redux)
  • React Query and SWR: 2.5% each

I also covered this in my "State of Redux 2021" talk.

On a related note, we recently released our new "RTK Query" API as part of Redux Toolkit 1.6. RTK Query is a data fetching and caching solution built on top of Redux Toolkit. It's similar to and inspired by React Query, Apollo, Urql, and SWR, but has a unique feature set and some nifty capabilities:

redux-toolkit.js.org/rtk-query/ove...

I don't have any hard usage stats on RTKQ so far, but we're seeing a rapid increase in the number of RTKQ questions we answer over in Reactiflux, and have gotten a lot of very positive feedback on it so far.

Collapse
 
nickytonline profile image
Nick Taylor

Thanks for chiming in Mark and thanks for all your work on Redux! 😎

Collapse
 
sambitsahoojs profile image
sambit sahoo

In vue 3 it's mostly Pinia (Vuex 5 soon) and zustand in React. Zustand is really good with a very intuitive API. My discussion here

Collapse
 
mrdulin profile image
official_dulin

Redux as always. RTK

Collapse
 
sethburtonhall profile image
Seth Hall • Edited

React Context often does the trick but using Redux in my current React contract, Zustand in Protege.dev Next.js app, and Vuex in Vue.js. I find React Context and Zustand fairly straight forward and enjoyable, Redux is complicated to set up but fine to use after setup and I LOVE Vuex.

Collapse
 
gdenn profile image
Dennis Groß (he/him)

My opinion might be controversy but I avoid any state management framework as long as possible.

I am not a huge fan of the excessive use of the Flux pattern. I just use frameworks-/libraries like redux if I really benefit from cashing data.

But most of the time I like to design my backend API in a way that I can get exactly the information that I need for e.g. a React Component. And then I just fetch the data freshly from the API every time. => no state management required.

Why do prefer this? It just reduces the overall complexity of my application.

That being said, if I have a use case that benefits from cashing I tend to use Redux.

Collapse
 
mremanuel profile image

Mostly Redux. Although, I'm beginning to think, if you don't need anything fancy, using Apollo client's local state management is a good idea.

After spending a few days reading the docs and messing around with it, I'm starting to see lots of cool stuff to do with Apollo Client. The new version that is.

Collapse
 
psiho profile image
Mirko Vukušić

MobX. Love on first sight, for years now. Frankly, still don't get it whay Redux is so popular. For me, MobX is kind of "automagic", like a global class(es) you just set up and (most of the time) forget how it works. It just does.

Collapse
 
peerreynders profile image
peerreynders

What exactly do you need it to accomplish? (rhetorical question)

Given your Redux perspective I recommend reading:

not to recommend either XState or Mobx but to better frame what capabilities your candidate solution needs to have.

Collapse
 
nickytonline profile image
Nick Taylor

I'm not so much looking for a solution myself, just curious what folks are using these days. I took David K. Piano's XState course on FEM and it was really great. I haven't tried Mobx though.

Collapse
 
pontakornth profile image
Pontakorn Paesaeng

I never got to the point where I really need a state management library. The valid use cases would be complex application such as e-commerce website, admin control panel, interactive e-learning system and more.

I don't really consider things like React Query or useSWR to be a complete state management library. They are more like library for simple fetching without headache.

Applications that are not complex would just need to handle input, processing, output and error. For example, a blog needs to fetch data from server then display content to users, a simple chat application would handling messages from other people and sending messages from the user. If the application is this simple, it would not need complex state management solution. At most, it may require some basic solution such as Context, useState, or useReducer.

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay