Which is Better State Management Libraries for React?
redux vs zustand vs xstate vs mobx vs react-query vs jotai vs recoil vs valtio
1 Year
reduxzustandxstatemobxreact-queryjotairecoilvaltioSimilar Packages:
What's State Management Libraries for React?

State management libraries are essential tools in React development, enabling developers to manage application state in a predictable and efficient manner. These libraries provide various methodologies for handling state, allowing for better organization, scalability, and maintainability of applications. They help in managing local and global state, asynchronous data fetching, and side effects, which are crucial for building complex user interfaces. Each library has its unique approach, catering to different needs and preferences, making it essential to understand their features and use cases for optimal selection.

NPM Package Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
redux10,176,57460,858290 kB3810 months agoMIT
zustand4,157,43847,11688.6 kB3a month agoMIT
xstate1,648,91727,0241.67 MB13523 days agoMIT
mobx1,553,52427,5064.32 MB6918 days agoMIT
react-query1,356,61842,1082.26 MB762 years agoMIT
jotai1,095,08018,495427 kB724 days agoMIT
recoil496,36019,5932.21 MB3212 years agoMIT
valtio428,0939,03375.4 kB32 months agoMIT
Feature Comparison: redux vs zustand vs xstate vs mobx vs react-query vs jotai vs recoil vs valtio

State Management Approach

  • redux: Redux uses a centralized store and a unidirectional data flow to manage application state. It emphasizes immutability and pure functions, making state changes predictable and easier to debug, but can introduce boilerplate code.
  • zustand: Zustand is a minimalistic state management library that uses hooks for managing state. It allows for a simple API and encourages the use of React's built-in features, making it lightweight and easy to integrate.
  • xstate: XState is a state management library based on finite state machines and statecharts. It provides a robust way to manage complex state transitions and side effects, making it ideal for applications with intricate workflows and states.
  • mobx: MobX employs an observable-based state management approach, allowing for automatic tracking of state changes and reactivity. It simplifies state management by allowing you to define observable state and reactions that automatically update when the state changes.
  • react-query: React Query focuses on server state management, providing tools for fetching, caching, and synchronizing server data with the client. It abstracts the complexities of data fetching and caching, making it easier to manage asynchronous data in React applications.
  • jotai: Jotai uses an atomic state management model, where each piece of state is an atom. This allows for granular updates and reactivity, ensuring that only the components that depend on a specific atom re-render when that atom's state changes.
  • recoil: Recoil introduces a state management model that combines the benefits of both atomic and derived state. It allows for fine-grained control over state and enables derived state calculations, making it suitable for complex applications with interdependent state.
  • valtio: Valtio offers a proxy-based state management approach, allowing for mutable state while keeping reactivity intact. It simplifies state management by enabling direct manipulation of state objects without the need for reducers or actions.

Learning Curve

  • redux: Redux has a steeper learning curve due to its concepts of actions, reducers, and middleware. It requires a good understanding of functional programming principles, which may be challenging for some developers.
  • zustand: Zustand is straightforward and easy to learn, with a minimal API that is intuitive for React developers. Its simplicity allows for quick onboarding.
  • xstate: XState has a higher learning curve, as it introduces state machines and statecharts, which may be unfamiliar to many developers. However, it provides a powerful model for managing complex states.
  • mobx: MobX is relatively easy to learn, particularly for those with a background in object-oriented programming. Its observable pattern is intuitive, but understanding the reactivity model may take some time for beginners.
  • react-query: React Query has a moderate learning curve, as it introduces concepts like caching and server state management. However, its documentation is comprehensive, aiding in the learning process.
  • jotai: Jotai has a low learning curve, especially for developers familiar with React hooks. Its API is straightforward and easy to grasp, making it accessible for newcomers to state management.
  • recoil: Recoil's learning curve is gentle for those familiar with React, as it integrates seamlessly with React's mental model. However, understanding its advanced features may require additional time.
  • valtio: Valtio is easy to learn, especially for those familiar with JavaScript proxies. Its API is simple and intuitive, allowing developers to quickly grasp its usage.

Performance

  • redux: Redux can introduce performance bottlenecks if not managed correctly, particularly with large state trees. However, using techniques like memoization and selectors can mitigate these issues.
  • zustand: Zustand is lightweight and performant, as it allows for direct state manipulation without unnecessary re-renders. Its simplicity contributes to efficient state management.
  • xstate: XState can be performant for complex state management, but the overhead of managing state machines may introduce some latency. Properly designed statecharts can optimize performance for intricate workflows.
  • mobx: MobX is highly performant due to its automatic dependency tracking and fine-grained reactivity. It minimizes re-renders by only updating components that directly depend on the changed observable state.
  • react-query: React Query excels in performance by caching server data and minimizing network requests. It intelligently refetches data only when necessary, improving the overall responsiveness of applications.
  • jotai: Jotai is optimized for performance, as it only re-renders components that depend on changed atoms. This fine-grained reactivity minimizes unnecessary renders and enhances application performance.
  • recoil: Recoil offers good performance through its atomic state model, ensuring that only components subscribed to changed atoms re-render. This selective rendering helps maintain application efficiency.
  • valtio: Valtio provides excellent performance by allowing mutable state while maintaining reactivity. Its proxy-based approach ensures efficient updates and minimal re-renders.

Extensibility

  • redux: Redux is highly extensible, with a rich ecosystem of middleware and libraries that enhance its functionality. Developers can create custom reducers and actions to fit their application needs.
  • zustand: Zustand is designed to be extensible with custom hooks and middleware, allowing developers to enhance its functionality and integrate it with other libraries.
  • xstate: XState is extensible through the use of custom state machines and transitions, allowing developers to define complex workflows and behaviors tailored to their applications.
  • mobx: MobX is extensible through decorators and custom observable structures, enabling developers to tailor the state management to their specific requirements.
  • react-query: React Query is extensible with custom hooks and query functions, allowing developers to integrate it seamlessly with other libraries and APIs, enhancing its capabilities.
  • jotai: Jotai is highly extensible, allowing developers to create custom atoms and hooks, making it adaptable to various application needs and architectures.
  • recoil: Recoil supports extensibility through its atom and selector model, enabling developers to create complex state relationships and derived state calculations easily.
  • valtio: Valtio is extensible by allowing developers to create custom proxies and state structures, making it flexible for various use cases and architectures.
How to Choose: redux vs zustand vs xstate vs mobx vs react-query vs jotai vs recoil vs valtio
  • jotai: Choose Jotai if you prefer a minimalistic and atomic state management approach that allows for fine-grained control over state updates and is easy to integrate with existing React applications.
README for redux

Redux Logo

Redux is a predictable state container for JavaScript apps.

It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test. On top of that, it provides a great developer experience, such as live code editing combined with a time traveling debugger.

You can use Redux together with React, or with any other view library. The Redux core is tiny (2kB, including dependencies), and has a rich ecosystem of addons.

Redux Toolkit is our official recommended approach for writing Redux logic. It wraps around the Redux core, and contains packages and functions that we think are essential for building a Redux app. Redux Toolkit builds in our suggested best practices, simplifies most Redux tasks, prevents common mistakes, and makes it easier to write Redux applications.

GitHub Workflow Status npm version npm downloads redux channel on discord

Installation

Create a React Redux App

The recommended way to start new apps with React and Redux Toolkit is by using our official Redux Toolkit + TS template for Vite, or by creating a new Next.js project using Next's with-redux template.

Both of these already have Redux Toolkit and React-Redux configured appropriately for that build tool, and come with a small example app that demonstrates how to use several of Redux Toolkit's features.

# Vite with our Redux+TS template
# (using the `degit` tool to clone and extract the template)
npx degit reduxjs/redux-templates/packages/vite-template-redux my-app

# Next.js using the `with-redux` template
npx create-next-app --example with-redux my-app

We do not currently have official React Native templates, but recommend these templates for standard React Native and for Expo:

  • https://github.com/rahsheen/react-native-template-redux-typescript
  • https://github.com/rahsheen/expo-template-redux-typescript
npm install @reduxjs/toolkit react-redux

For the Redux core library by itself:

npm install redux

For more details, see the Installation docs page.

Documentation

The Redux core docs are located at https://redux.js.org, and include the full Redux tutorials, as well usage guides on general Redux patterns:

The Redux Toolkit docs are available at https://redux-toolkit.js.org, including API references and usage guides for all of the APIs included in Redux Toolkit.

Learn Redux

Redux Essentials Tutorial

The Redux Essentials tutorial is a "top-down" tutorial that teaches "how to use Redux the right way", using our latest recommended APIs and best practices. We recommend starting there.

Redux Fundamentals Tutorial

The Redux Fundamentals tutorial is a "bottom-up" tutorial that teaches "how Redux works" from first principles and without any abstractions, and why standard Redux usage patterns exist.

Help and Discussion

The #redux channel of the Reactiflux Discord community is our official resource for all questions related to learning and using Redux. Reactiflux is a great place to hang out, ask questions, and learn - please come and join us there!

Before Proceeding Further

Redux is a valuable tool for organizing your state, but you should also consider whether it's appropriate for your situation. Please don't use Redux just because someone said you should - instead, please take some time to understand the potential benefits and tradeoffs of using it.

Here are some suggestions on when it makes sense to use Redux:

  • You have reasonable amounts of data changing over time
  • You need a single source of truth for your state
  • You find that keeping all your state in a top-level component is no longer sufficient

Yes, these guidelines are subjective and vague, but this is for a good reason. The point at which you should integrate Redux into your application is different for every user and different for every application.

For more thoughts on how Redux is meant to be used, please see:

Basic Example

The whole global state of your app is stored in an object tree inside a single store. The only way to change the state tree is to create an action, an object describing what happened, and dispatch it to the store. To specify how state gets updated in response to an action, you write pure reducer functions that calculate a new state based on the old state and the action.

Redux Toolkit simplifies the process of writing Redux logic and setting up the store. With Redux Toolkit, the basic app logic looks like:

import { createSlice, configureStore } from '@reduxjs/toolkit'

const counterSlice = createSlice({
  name: 'counter',
  initialState: {
    value: 0
  },
  reducers: {
    incremented: state => {
      // Redux Toolkit allows us to write "mutating" logic in reducers. It
      // doesn't actually mutate the state because it uses the Immer library,
      // which detects changes to a "draft state" and produces a brand new
      // immutable state based off those changes
      state.value += 1
    },
    decremented: state => {
      state.value -= 1
    }
  }
})

export const { incremented, decremented } = counterSlice.actions

const store = configureStore({
  reducer: counterSlice.reducer
})

// Can still subscribe to the store
store.subscribe(() => console.log(store.getState()))

// Still pass action objects to `dispatch`, but they're created for us
store.dispatch(incremented())
// {value: 1}
store.dispatch(incremented())
// {value: 2}
store.dispatch(decremented())
// {value: 1}

Redux Toolkit allows us to write shorter logic that's easier to read, while still following the original core Redux behavior and data flow.

Logo

You can find the official logo on GitHub.

Change Log

This project adheres to Semantic Versioning. Every release, along with the migration instructions, is documented on the GitHub Releases page.

License

MIT