redux vs mobx vs vuex vs @ngrx/store
State Management Libraries Comparison
1 Year
reduxmobxvuex@ngrx/storeSimilar Packages:
What's State Management Libraries?

State management libraries are essential tools in modern web development, enabling developers to manage application state in a predictable and efficient manner. These libraries provide a structured approach to handling state changes, making it easier to maintain and debug applications, especially as they grow in complexity. They facilitate communication between components, ensuring that the UI reflects the current state of the application. Each library has its own unique features, design principles, and use cases, catering to different development needs and preferences.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
redux12,220,69961,146290 kB41a year agoMIT
mobx1,760,33227,8344.33 MB65a month agoMIT
vuex1,711,23728,460271 kB144-MIT
@ngrx/store755,0958,156636 kB6614 days agoMIT
Feature Comparison: redux vs mobx vs vuex vs @ngrx/store

Design Principles

  • redux:

    Redux is built around a strict unidirectional data flow and the concept of a single source of truth. It encourages the use of pure functions (reducers) to manage state transitions, which enhances predictability and makes debugging easier through time-travel debugging capabilities.

  • mobx:

    MobX embraces a more reactive programming model, allowing developers to define observable states that automatically update the UI when changes occur. This results in a more intuitive and less verbose code structure, focusing on simplicity and direct state manipulation.

  • vuex:

    Vuex is designed specifically for Vue.js applications, utilizing a centralized store to manage state across components. It follows a similar pattern to Redux but integrates deeply with Vue's reactivity system, allowing for seamless state updates and component interactions.

  • @ngrx/store:

    @ngrx/store follows the Redux pattern and emphasizes immutability and unidirectional data flow. It promotes a clear separation of concerns, where actions, reducers, and selectors are distinctly defined, making state changes predictable and traceable.

Learning Curve

  • redux:

    Redux has a steeper learning curve due to its strict principles and the need to understand concepts like actions, reducers, and middleware. However, mastering Redux can lead to a deep understanding of state management patterns, which is beneficial for large-scale applications.

  • mobx:

    MobX has a relatively low learning curve, particularly for those familiar with JavaScript. Its straightforward API and reactive nature make it easy to adopt, allowing developers to focus on building features rather than managing boilerplate code.

  • vuex:

    Vuex is generally easier to learn for developers already familiar with Vue.js, as it builds upon Vue's reactivity principles. Its documentation is comprehensive, making it accessible for those transitioning from Vue components to state management.

  • @ngrx/store:

    @ngrx/store has a moderate learning curve, especially for developers new to reactive programming and RxJS. Understanding the concepts of actions, reducers, and effects is crucial, but once grasped, it provides powerful tools for managing complex state scenarios.

Mutability

  • redux:

    Redux strictly adheres to immutability, requiring developers to return new state objects from reducers. This practice ensures that state changes are explicit and traceable, which is beneficial for debugging and maintaining application state over time.

  • mobx:

    MobX allows for mutable state, enabling direct modifications to observable properties. This flexibility can lead to simpler code but requires careful management to avoid unintended side effects, especially in larger applications.

  • vuex:

    Vuex promotes immutability in state management, encouraging developers to use mutations to change state. This ensures that all state changes are trackable and predictable, aligning with Vue's reactivity system.

  • @ngrx/store:

    @ngrx/store enforces immutability by design, requiring developers to create new state objects rather than modifying existing ones. This approach helps prevent unintended side effects and makes state changes predictable, which is crucial for debugging and testing.

Extensibility

  • redux:

    Redux is known for its extensibility through middleware, enabling developers to add functionality like logging, crash reporting, and asynchronous actions. The ecosystem around Redux is vast, with numerous libraries and tools available to enhance its capabilities.

  • mobx:

    MobX is inherently extensible, allowing developers to create custom decorators and utilities to enhance state management. Its reactive nature makes it easy to integrate with other libraries and frameworks, providing flexibility in application architecture.

  • vuex:

    Vuex offers extensibility through plugins, allowing developers to add custom functionality to the store. This feature enables the integration of additional capabilities like persistence, logging, and more, while maintaining the core principles of Vuex.

  • @ngrx/store:

    @ngrx/store is highly extensible, allowing developers to create custom middleware and effects to handle complex asynchronous operations. Its modular architecture supports the addition of new features without disrupting existing functionality.

Performance

  • redux:

    Redux can face performance challenges with large state trees and frequent updates, but techniques like memoization and selective rendering can mitigate these issues. The predictable state updates make it easier to optimize performance in complex applications.

  • mobx:

    MobX is designed for performance, automatically tracking dependencies and minimizing unnecessary re-renders. Its reactive nature allows for efficient updates, making it suitable for applications that require high responsiveness and real-time data handling.

  • vuex:

    Vuex is optimized for Vue.js applications, ensuring efficient state updates through its reactivity system. It handles large state management needs well, but developers should be mindful of performance implications when using deep state structures.

  • @ngrx/store:

    @ngrx/store leverages RxJS for efficient state management, enabling fine-grained control over state updates. Its use of observables can lead to optimized performance, especially in applications with complex state interactions and large data sets.

How to Choose: redux vs mobx vs vuex vs @ngrx/store
  • redux:

    Choose Redux if you need a predictable state container that follows a strict unidirectional data flow. It is particularly useful for large applications with complex state management needs, and its middleware capabilities allow for advanced features like asynchronous actions and logging.

  • mobx:

    Choose MobX if you prefer a more straightforward and less boilerplate-heavy approach to state management. MobX uses observable state and allows for automatic updates to the UI, making it ideal for applications where simplicity and performance are priorities, especially in React-based projects.

  • vuex:

    Choose Vuex if you are developing applications with Vue.js and require a centralized state management solution that integrates well with Vue's reactivity system. Vuex provides a clear structure for managing state and is designed to work seamlessly with Vue components.

  • @ngrx/store:

    Choose @ngrx/store if you are working with Angular applications and need a robust, reactive state management solution that integrates seamlessly with Angular's ecosystem. It leverages RxJS for reactive programming, making it suitable for applications that require complex state interactions.

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