The Best React State Management

By Harry WolffUpdated December 13th, 2021

The Best React State Management Image

There isn't one best React State Management library.

Each option has their own different set of tradeoffs, and depending on your usecase one set of tradeoffs may be better or worse.

The closest option for one-size-fits-all is React Context, fortunately provided out of the box by React.

It doesn't provide much beyond making data globally accessible, but in terms of tradeoffs it hits the right balance of value and flexibility.

If you're looking to get started with state management, start with React Context.

What is state management?

Many applications need to store data in one location, such that it can be stored and accessed anywhere.

Additionally some applications have performance needs, loading and displaying heavy data sets that require optimizations to support performant updates.

State management libraries address these two concerns: providing structure to store your data globally in an optimized manner.

React Context

React Context is the simplest way to manage your state.

It comes by default with React which makes it easy to get started with.

A nice feature of Context is you can make as many as you want, with each context focused on slice of your state, letting you focus its contents and behavior.

If the state in your Context grows complex is deeply nested then you should add Immer to your Context. Immer makes it easy and error-free to handle deeply nested state object updates.

I'd actually encourage you to start with Immer from the start, no matter how simple or complex the state is in your context. The developer experience of Immer is that great that it should be a default addition to your state management solution.

redux

Redux is the grandfather of all React state management solutions. When it was first introduced it revolutionized the space, causing the entire community to rethink how to structure their data and manage their state.

Since its original introduction the novelty has worn off yet its utility remains just as useful.

The biggest disadvantage to Redux is that it doesn't provide much structure or opinions, however that has largely been solved with the introduction of Redux Toolkit, a toolset for Redux that codifies best practices for Redux and provides highly useful utilities.

The biggest hurdle to using Redux is to 'think in Redux'. Redux require you to learn concepts such as reducer, action creators, actions, and slices. These concepts are shared in other parts of the React ecosystem, but they're a strict requirement for using Redux.

Beyond those concepts, Redux itself is a simple library and simple to use. It doesn't provide many optimizations out of the box and requires more involvement from the developer than other state management libraries, but its power comes from its simplicity.

If you have fairly vanilla state requirements then Redux is a fine choice.

zustand

Zustand is a light-weight alternative to Redux that comes with built-in opinionated APIs to structure and access your data. Additionally it provides performance optimizations such that accessing only a slice of data will only cause your component to be updated when that slice changes.

Choose Zustand if you're looking for a lighter weight alternative to Redux with some strong primitives.

MobX

MobX is as close to magic as you can get in programming. By leaning into functionally reactive programming, MobX provides a state management solution that requires almost no API knowledge.

After making your data reactive and your component aware that it's consuming MobX code, all getters and setters look like plain old JavaScript object methods.

MobX tends to be the easiest migration path for users coming from an object-oriented background (such as Java), however its easy API makes it easy to use by anyone.

Recoil

Recoil is a newer entrant into the space, and it's highly focused on performance.

It has a large API (compared to the other options on this page) and requires leanring its concepts, however once you're up to speed its performance promises are its biggest selling point.

If you have an app with highly complex data needs with high performance requirements, then Recoil may be for you.