redux vs mobx vs vuex vs effector vs react-query vs recoil vs xstate vs zustand
状態管理ライブラリ
reduxmobxvuexeffectorreact-queryrecoilxstatezustand類似パッケージ:

状態管理ライブラリ

状態管理ライブラリは、アプリケーションの状態を管理し、コンポーネント間でのデータの共有を容易にするためのツールです。これらのライブラリは、特に大規模なアプリケーションにおいて、状態の一貫性を保ち、データフローを明確にすることを目的としています。各ライブラリは異なるアプローチを持ち、特定のユースケースや開発スタイルに応じて選択されます。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
redux42,217,46161,508290 kB493年前MIT
mobx3,957,57528,2064.8 MB566日前MIT
vuex1,698,57328,321271 kB143-MIT
effector04,8491.59 MB1591年前MIT
react-query050,2052.26 MB1244年前MIT
recoil019,4312.21 MB3203年前MIT
xstate030,0622.29 MB1231ヶ月前MIT
zustand058,60895.2 kB513日前MIT

機能比較: redux vs mobx vs vuex vs effector vs react-query vs recoil vs xstate vs zustand

リアクティブ性

  • redux:

    Reduxは、状態の変更をアクションを通じて明示的に管理し、状態のトレースが容易です。状態の変更がどこで起こったかを追跡できます。

  • mobx:

    MobXは、オブジェクトの変更を監視し、変更があった場合に自動的にUIを更新します。これにより、開発者は状態の変化に集中できます。

  • vuex:

    Vuexは、Vueコンポーネントの状態をリアクティブに管理し、状態の変更を中央集権的に管理します。

  • effector:

    Effectorは、リアクティブプログラミングを基盤としており、状態の変更を即座に反映します。これにより、複雑なデータフローを簡潔に管理できます。

  • react-query:

    React Queryは、サーバーから取得したデータの変更をリアルタイムで反映し、キャッシング機能によりパフォーマンスを向上させます。

  • recoil:

    Recoilは、状態の変更をリアクティブに管理し、コンポーネント間でのデータの共有を容易にします。特に、状態の依存関係を明示的に定義できます。

  • xstate:

    XStateは、状態遷移を明示的に定義でき、状態の変更がどのように行われるかを可視化できます。

  • zustand:

    Zustandは、シンプルなAPIを持ち、状態の変更を簡単に管理できます。軽量でありながら、リアクティブな更新が可能です。

学習曲線

  • redux:

    Reduxは、概念が多く、学習曲線が急ですが、状態管理のベストプラクティスを学ぶ良い機会でもあります。

  • mobx:

    MobXは、シンプルなAPIを持ち、比較的短期間で習得できます。オブジェクト指向に慣れている開発者には特に適しています。

  • vuex:

    Vuexは、Vue.jsに特化しているため、Vueの知識があれば比較的簡単に学べます。

  • effector:

    Effectorは、リアクティブプログラミングの概念を理解する必要があるため、学習曲線がやや急です。

  • react-query:

    React Queryは、APIとのやり取りに特化しているため、特定のユースケースに対する学習が必要ですが、基本的な使い方は簡単です。

  • recoil:

    Recoilは、Reactのエコシステムに統合されているため、Reactに慣れている開発者には比較的学びやすいです。

  • xstate:

    XStateは、状態遷移の概念を理解する必要があるため、学習曲線がやや急ですが、複雑な状態管理に対する理解が深まります。

  • zustand:

    Zustandは、シンプルなAPIを持ち、すぐに使い始めることができるため、学習曲線は非常に緩やかです。

状態の管理方法

  • redux:

    Reduxは、アクションとリデューサーを使用して状態を管理し、状態の変更が明示的にトリガーされます。

  • mobx:

    MobXは、オブジェクトのプロパティを監視し、変更があった場合に自動的にUIを更新します。状態の変更が直感的に行えます。

  • vuex:

    Vuexは、ストアを使用して状態を管理し、ミューテーションを通じて状態を変更します。

  • effector:

    Effectorは、ストアとエフェクトを使用して状態を管理します。これにより、状態の変更が明示的にトリガーされ、デバッグが容易です。

  • react-query:

    React Queryは、サーバーからのデータをキャッシュし、必要に応じて更新します。これにより、効率的なデータ管理が可能です。

  • recoil:

    Recoilは、アトムとセレクタを使用して状態を管理し、状態の依存関係を明示的に定義できます。

  • xstate:

    XStateは、状態遷移を定義し、状態の変更を明示的に管理します。

  • zustand:

    Zustandは、シンプルなストアを使用して状態を管理し、必要なときに状態を更新できます。

パフォーマンス

  • redux:

    Reduxは、状態の変更が明示的であるため、パフォーマンスの最適化が可能ですが、適切な設計が求められます。

  • mobx:

    MobXは、必要な部分だけを更新するため、パフォーマンスが良好です。特に、オブジェクトの変更が少ない場合に効果を発揮します。

  • vuex:

    Vuexは、Vueのリアクティブシステムを活用しているため、パフォーマンスが良好です。

  • effector:

    Effectorは、状態の変更が効率的に行われるため、パフォーマンスが高いです。特に、大規模なアプリケーションにおいてもスムーズに動作します。

  • react-query:

    React Queryは、データのキャッシングとフェッチングを効率的に行うため、パフォーマンスが向上します。

  • recoil:

    Recoilは、状態の依存関係を管理することで、必要な部分だけを再レンダリングし、パフォーマンスを最適化します。

  • xstate:

    XStateは、状態遷移が明示的に定義されているため、パフォーマンスが高く、複雑な状態管理に適しています。

  • zustand:

    Zustandは、軽量でシンプルな設計のため、パフォーマンスが高く、特に小規模なアプリケーションに適しています。

選び方: redux vs mobx vs vuex vs effector vs react-query vs recoil vs xstate vs zustand

  • redux:

    Reduxは、状態管理のための一貫したアプローチを提供し、特に大規模なアプリケーションでの状態のトレースが必要な場合に選択します。

  • mobx:

    MobXは、シンプルな状態管理を提供し、リアクティブなデータバインディングが必要な場合に適しています。特に、オブジェクト指向プログラミングに慣れている開発者に向いています。

  • vuex:

    Vuexは、Vue.jsアプリケーション専用の状態管理ライブラリで、Vueのコンポーネント間での状態共有が必要な場合に選択してください。

  • effector:

    Effectorは、リアクティブプログラミングを重視し、パフォーマンスが重要なアプリケーションに適しています。状態の変更を効率的に管理したい場合に選択してください。

  • react-query:

    React Queryは、サーバーからのデータフェッチングとキャッシングを簡素化するために設計されています。APIとのやり取りが多いアプリケーションに最適です。

  • recoil:

    Recoilは、Reactのために設計された状態管理ライブラリで、コンポーネントの状態を簡単に共有したい場合に選択してください。特に、Reactのエコシステムに深く統合されている点が魅力です。

  • xstate:

    XStateは、状態遷移を明示的に定義できるため、複雑な状態管理が必要なアプリケーションに適しています。状態遷移の可視化が重要な場合に選択します。

  • zustand:

    Zustandは、シンプルで軽量な状態管理を提供し、特に小規模なアプリケーションやプロトタイプに適しています。簡単に導入したい場合に選択してください。

redux のREADME

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:

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