redux vs zustand vs xstate vs mobx vs jotai vs react-query vs valtio vs recoil
状態管理ライブラリ
reduxzustandxstatemobxjotaireact-queryvaltiorecoil類似パッケージ:
状態管理ライブラリ

状態管理ライブラリは、アプリケーションの状態を効率的に管理し、コンポーネント間でのデータの共有を容易にするためのツールです。これらのライブラリは、特にReactアプリケーションにおいて、状態の一貫性を保ちながら、ユーザーインターフェースの反応性を向上させることを目的としています。各ライブラリは異なるアプローチを持ち、特定のユースケースに最適化されています。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
redux16,548,12161,418290 kB462年前MIT
zustand12,479,79155,95994.3 kB32日前MIT
xstate2,463,23328,9742.19 MB1691ヶ月前MIT
mobx2,179,04928,1104.35 MB782ヶ月前MIT
jotai2,015,71620,795501 kB616時間前MIT
react-query1,327,31847,6022.26 MB1293年前MIT
valtio1,005,28610,031104 kB31ヶ月前MIT
recoil484,30419,5622.21 MB3233年前MIT
機能比較: redux vs zustand vs xstate vs mobx vs jotai vs react-query vs valtio vs recoil

状態管理のアプローチ

  • redux:

    Reduxは単一のストアを使用し、アクションとリデューサーを通じて状態を管理します。これにより、状態の変更が予測可能になります。

  • mobx:

    MobXはリアクティブプログラミングを基盤としており、状態の変更を自動的に追跡し、UIを自動的に更新します。

  • jotai:

    Jotaiはアトムベースの状態管理を採用しており、各アトムが独立しているため、必要な状態のみを選択的に管理できます。

  • react-query:

    React Queryはサーバー状態の管理に特化しており、データのフェッチやキャッシングを簡単に行えます。

  • recoil:

    Recoilはアトムとセレクタを使用して、状態の依存関係を明示的に管理します。これにより、状態の変更が他の状態に与える影響を簡単に把握できます。

パフォーマンス

  • redux:

    Reduxは状態の変更が明示的であるため、パフォーマンスの最適化が容易です。

  • mobx:

    MobXは状態の変更を自動的に追跡するため、パフォーマンスが高く、UIの更新がスムーズです。

  • jotai:

    Jotaiは必要な状態のみを管理するため、パフォーマンスが高く、不要な再レンダリングを避けることができます。

  • react-query:

    React Queryはデータのキャッシングを行うため、サーバーへのリクエストを最小限に抑え、パフォーマンスを向上させます。

  • recoil:

    Recoilは状態の依存関係を管理するため、必要な部分のみが再レンダリングされ、パフォーマンスが向上します。

学習曲線

  • redux:

    Reduxはアクションやリデューサーの概念を理解する必要があり、学習曲線が急ですが、強力な状態管理を提供します。

  • mobx:

    MobXはリアクティブプログラミングの概念を理解する必要があり、やや学習曲線が急ですが、強力な機能を提供します。

  • jotai:

    JotaiはシンプルなAPIを持っており、学習曲線が緩やかで、すぐに使い始めることができます。

  • react-query:

    React Queryはデータフェッチの概念を理解する必要がありますが、APIが直感的で使いやすいため、比較的学習しやすいです。

  • recoil:

    RecoilはReactのコンテキストAPIに基づいているため、Reactに慣れている開発者には学習しやすいです。

拡張性

  • redux:

    Reduxはミドルウェアを使用することで、機能を拡張しやすく、カスタマイズが可能です。

  • mobx:

    MobXはプラグインや拡張機能をサポートしており、柔軟な拡張が可能です。

  • jotai:

    Jotaiはシンプルな設計のため、必要に応じて簡単に拡張できます。

  • react-query:

    React Queryはカスタムフックを作成することで、拡張性が高く、特定のニーズに合わせたデータ管理が可能です。

  • recoil:

    Recoilはアトムとセレクタを組み合わせることで、柔軟な拡張が可能です。

デバッグツール

  • redux:

    ReduxはRedux DevToolsを使用して、状態の変更を詳細に追跡でき、デバッグが容易です。

  • mobx:

    MobXは強力なデバッグツールを提供しており、状態の変更を視覚的に追跡できます。

  • jotai:

    Jotaiはシンプルな状態管理のため、デバッグが容易で、状態の追跡が簡単です。

  • react-query:

    React Queryはデバッグツールが充実しており、サーバー状態の管理が容易です。

  • recoil:

    RecoilはReact DevToolsと統合されており、状態のトラッキングが容易です。

選び方: redux vs zustand vs xstate vs mobx vs jotai vs react-query vs valtio vs recoil
  • redux:

    大規模なアプリケーションでの一貫した状態管理を求める場合、Reduxが適しています。ミドルウェアや開発者ツールが豊富で、状態の変更を予測可能にします。

  • zustand:

    軽量で簡潔なAPIを求める場合、Zustandが最適です。フックを使った状態管理が可能で、簡単に導入できます。

  • xstate:

    状態遷移を明示的に管理したい場合、XStateが適しています。状態マシンを使って、複雑な状態管理を視覚的に表現できます。

  • mobx:

    リアクティブプログラミングを重視し、状態の変更を自動的に追跡したい場合はMobXが良い選択です。特に大規模なアプリケーションでの状態管理に強みがあります。

  • jotai:

    シンプルで軽量な状態管理を求める場合、Jotaiが適しています。アトムベースのアプローチにより、必要な状態のみを管理し、パフォーマンスを最適化します。

  • react-query:

    サーバーからのデータ取得やキャッシングを効率的に行いたい場合、React Queryが最適です。データのフェッチやキャッシュ管理を簡素化し、サーバー状態を扱うのに特化しています。

  • valtio:

    シンプルで直感的なAPIを持つValtioは、プロキシベースの状態管理を提供します。状態の変更がリアルタイムで反映されるため、使いやすさが特徴です。

  • recoil:

    ReactのコンテキストAPIを活用しつつ、より柔軟な状態管理を求める場合はRecoilが適しています。アトムとセレクタを使った状態管理が可能です。

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