redux vs redux-thunk vs mobx vs react-query vs redux-saga vs @ngrx/store vs apollo-client vs @ngrx/data
State Management Libraries Comparison
1 Year
reduxredux-thunkmobxreact-queryredux-saga@ngrx/storeapollo-client@ngrx/dataSimilar Packages:
What's State Management Libraries?

State management libraries are essential tools in web development that help manage the state of applications, especially as they grow in complexity. These libraries provide structured ways to handle data flow and state updates, ensuring that the UI remains in sync with the underlying data. They often facilitate predictable state transitions, making it easier to debug and maintain applications. Each library has its own approach and philosophy, catering to different use cases and developer preferences.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
redux14,931,89061,258290 kB432 years agoMIT
redux-thunk7,650,77717,76126.8 kB12 years agoMIT
mobx1,957,48427,9504.33 MB693 months agoMIT
react-query1,596,54045,6632.26 MB1132 years agoMIT
redux-saga1,312,91122,532221 kB43a year agoMIT
@ngrx/store783,2588,222645 kB84a month agoMIT
apollo-client554,42019,588-5075 years agoMIT
@ngrx/data27,2698,2221.12 MB84a month agoMIT
Feature Comparison: redux vs redux-thunk vs mobx vs react-query vs redux-saga vs @ngrx/store vs apollo-client vs @ngrx/data

State Management Approach

  • redux:

    Redux uses a unidirectional data flow and a centralized store, making it easy to understand how data changes over time, which is particularly useful in large applications.

  • redux-thunk:

    Redux Thunk allows action creators to return functions instead of actions, enabling asynchronous logic to be written directly in the action creators, making it simpler to handle side effects.

  • mobx:

    MobX uses observable state and reactions, allowing for automatic updates to the UI when the state changes, providing a more intuitive and less verbose approach to state management.

  • react-query:

    React Query abstracts away the complexity of managing server state, providing hooks for fetching, caching, and synchronizing data with the server, making it easy to keep the UI in sync with the backend.

  • redux-saga:

    Redux Saga utilizes generator functions to manage side effects, allowing for more complex asynchronous workflows while keeping the action creators and reducers clean and focused.

  • @ngrx/store:

    @ngrx/store follows the Redux pattern, utilizing a single immutable state tree and pure functions (reducers) to manage state transitions, ensuring predictability and traceability.

  • apollo-client:

    Apollo Client manages both local and remote data with a focus on GraphQL, providing features like caching, optimistic UI updates, and real-time data synchronization.

  • @ngrx/data:

    @ngrx/data simplifies state management by providing a higher-level API for managing entity collections, reducing the need for boilerplate code typically associated with @ngrx/store.

Learning Curve

  • redux:

    Redux has a steep learning curve due to its concepts of immutability, pure functions, and middleware, which can be challenging for beginners to grasp.

  • redux-thunk:

    Redux Thunk has a relatively low learning curve, as it builds on the existing Redux concepts and allows for straightforward handling of asynchronous actions.

  • mobx:

    MobX is known for its low learning curve, as it allows developers to manage state with minimal boilerplate and provides a more intuitive reactive programming model.

  • react-query:

    React Query is designed to be easy to learn and use, especially for React developers, as it integrates seamlessly with React's component model and hooks.

  • redux-saga:

    Redux Saga has a higher learning curve compared to other Redux middleware due to its use of generator functions and the complexity of managing side effects, which may require additional time to understand.

  • @ngrx/store:

    @ngrx/store has a steeper learning curve due to its reliance on the Redux pattern and concepts like immutability and pure functions, which may require additional understanding for new developers.

  • apollo-client:

    Apollo Client has a manageable learning curve, particularly for developers familiar with GraphQL. Its documentation is comprehensive, making it easier to get started with data management.

  • @ngrx/data:

    @ngrx/data has a moderate learning curve, especially for developers familiar with Angular and RxJS, as it builds on top of these technologies.

Performance

  • redux:

    Redux can suffer from performance bottlenecks if the state tree becomes too large or if there are too many subscribers to the store. Proper use of selectors and memoization can mitigate these issues.

  • redux-thunk:

    Redux Thunk is lightweight and does not introduce significant performance overhead, but it may lead to less organized code if not used judiciously, especially in larger applications.

  • mobx:

    MobX is highly performant due to its fine-grained reactivity, ensuring that only components that depend on changed state are re-rendered, minimizing unnecessary updates.

  • react-query:

    React Query enhances performance by caching server responses and automatically updating the UI when data changes, reducing the need for manual state management and improving responsiveness.

  • redux-saga:

    Redux Saga's performance is generally good, but it can introduce overhead due to the complexity of managing side effects. However, it allows for more efficient handling of complex asynchronous flows.

  • @ngrx/store:

    @ngrx/store can lead to performance issues if not optimized correctly, as frequent state updates may trigger unnecessary re-renders. However, it provides tools like selectors to optimize performance.

  • apollo-client:

    Apollo Client excels in performance with its caching mechanisms, allowing for efficient data retrieval and reducing the number of network requests, which enhances the user experience.

  • @ngrx/data:

    @ngrx/data optimizes performance by leveraging Angular's change detection and RxJS for reactive programming, ensuring efficient updates to the UI based on state changes.

Use Cases

  • redux:

    Redux is best for large-scale JavaScript applications that need a predictable state container, especially when dealing with complex state interactions and side effects.

  • redux-thunk:

    Redux Thunk is suitable for applications that need a straightforward way to handle asynchronous actions without the complexity of sagas, making it a good choice for simpler use cases.

  • mobx:

    MobX is well-suited for applications that require a simple and reactive state management solution, particularly in React applications where minimal boilerplate is desired.

  • react-query:

    React Query is designed for applications that heavily interact with server data, making it an excellent choice for data-fetching scenarios where real-time updates are crucial.

  • redux-saga:

    Redux Saga is ideal for applications that require complex asynchronous workflows, such as those involving multiple API calls or intricate side effects that need to be managed in a structured way.

  • @ngrx/store:

    @ngrx/store is ideal for complex Angular applications where a centralized state management solution is necessary to manage interactions between various components and services.

  • apollo-client:

    Apollo Client is perfect for applications that consume GraphQL APIs, providing a robust solution for managing both local and remote data seamlessly.

  • @ngrx/data:

    @ngrx/data is best suited for Angular applications that require simplified entity management, particularly when dealing with CRUD operations and data synchronization.

How to Choose: redux vs redux-thunk vs mobx vs react-query vs redux-saga vs @ngrx/store vs apollo-client vs @ngrx/data
  • redux:

    Select Redux if you need a predictable state container for JavaScript apps. It is suitable for large applications with complex state management needs, providing a clear structure and middleware support for handling side effects.

  • redux-thunk:

    Choose Redux Thunk if you need a simple middleware for handling asynchronous actions in Redux. It is lightweight and allows you to write action creators that return a function instead of an action, making it easier to handle side effects.

  • mobx:

    Opt for MobX if you prefer a more reactive programming model with less boilerplate. MobX allows for automatic dependency tracking and provides a straightforward way to manage state in both React and non-React applications.

  • react-query:

    Choose React Query for managing server state in React applications. It simplifies data fetching, caching, and synchronization with the server, making it ideal for applications with frequent data updates.

  • redux-saga:

    Use Redux Saga if your application requires complex asynchronous operations. It allows you to manage side effects in a more manageable way using generator functions, making it easier to test and maintain asynchronous flows.

  • @ngrx/store:

    Select @ngrx/store if you require a reactive state management solution for Angular applications. It follows the Redux pattern and is suitable for applications that need a centralized store to manage complex state interactions.

  • apollo-client:

    Use Apollo Client if you are working with GraphQL APIs. It provides powerful caching and state management capabilities, allowing you to manage both local and remote data efficiently in a unified way.

  • @ngrx/data:

    Choose @ngrx/data if you are using Angular and need a simple way to manage entity data with a focus on reducing boilerplate code. It integrates seamlessly with Angular's dependency injection and RxJS, making it ideal for Angular 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