redux vs zustand vs jotai vs mobx-react-lite vs react-query vs recoil
状態管理ライブラリ
reduxzustandjotaimobx-react-litereact-queryrecoil類似パッケージ:
状態管理ライブラリ

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

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
redux18,035,02961,428290 kB482年前MIT
zustand15,087,65056,15994.3 kB317日前MIT
jotai2,558,72220,841507 kB97日前MIT
mobx-react-lite2,204,15928,121424 kB783ヶ月前MIT
react-query1,490,87747,8222.26 MB1513年前MIT
recoil516,67819,5622.21 MB3233年前MIT
機能比較: redux vs zustand vs jotai vs mobx-react-lite vs react-query vs recoil

状態管理のアプローチ

  • redux:

    Reduxは、ストアを中心に状態を管理し、アクションを通じて状態を変更します。これにより、状態の予測可能性が向上します。

  • zustand:

    Zustandは、フックベースのシンプルなAPIを提供し、状態管理を直感的に行えます。

  • jotai:

    Jotaiは、原子状態を使用しており、状態を小さな単位で管理します。これにより、必要な部分だけを再レンダリングし、パフォーマンスを向上させます。

  • mobx-react-lite:

    MobX-React-Liteは、リアクティブな状態管理を提供し、状態の変更を自動的に追跡します。これにより、UIが常に最新の状態を反映します。

  • react-query:

    React Queryは、サーバーからのデータ取得を中心に設計されており、データのフェッチングやキャッシングを簡素化します。

  • recoil:

    Recoilは、状態をアトムとセレクタで管理し、コンポーネント間での状態の共有を容易にします。

学習曲線

  • redux:

    Reduxは、アクションやリデューサーの概念を理解する必要があるため、学習曲線が急です。

  • zustand:

    Zustandは、非常にシンプルなAPIを持ち、すぐに使い始められるため、学習コストが低いです。

  • jotai:

    Jotaiは、シンプルなAPIを持ち、学習コストが低いため、初心者にも扱いやすいです。

  • mobx-react-lite:

    MobX-React-Liteは、リアクティブプログラミングの概念を理解する必要がありますが、使い始めるのは比較的簡単です。

  • react-query:

    React Queryは、データフェッチングの概念を理解する必要がありますが、直感的なAPIのおかげで学習は容易です。

  • recoil:

    Recoilは、ReactのコンテキストAPIに慣れていると学習がスムーズですが、初めてのユーザーには少し複雑に感じるかもしれません。

パフォーマンス

  • redux:

    Reduxは、状態の変更が明示的であるため、パフォーマンスの最適化が可能ですが、適切に設計しないとパフォーマンスが低下する可能性があります。

  • zustand:

    Zustandは、シンプルなAPIと軽量な設計により、パフォーマンスが高く、必要な機能だけを持つため、オーバーヘッドが少ないです。

  • jotai:

    Jotaiは、必要な部分だけを再レンダリングするため、パフォーマンスが高いです。

  • mobx-react-lite:

    MobX-React-Liteは、状態の変更を自動的に追跡し、効率的にUIを更新するため、パフォーマンスが優れています。

  • react-query:

    React Queryは、データのキャッシングとプリフェッチングを行うため、サーバーとの通信を最適化し、パフォーマンスを向上させます。

  • recoil:

    Recoilは、アトム単位で状態を管理するため、必要なコンポーネントだけが再レンダリングされ、パフォーマンスが向上します。

拡張性

  • redux:

    Reduxは、ミドルウェアを使用して機能を拡張することができ、非常に柔軟です。

  • zustand:

    Zustandは、シンプルなAPIのため、必要に応じて機能を追加しやすいです。

  • jotai:

    Jotaiは、シンプルな設計のため、必要に応じて拡張が容易です。

  • mobx-react-lite:

    MobX-React-Liteは、プラグインや拡張機能を通じて機能を追加することができます。

  • react-query:

    React Queryは、カスタムフックを作成することで、機能を拡張することができます。

  • recoil:

    Recoilは、アトムやセレクタを使用して、状態管理のロジックを簡単に拡張できます。

ユースケース

  • redux:

    Reduxは、大規模なアプリケーションや複雑な状態管理が必要な場合に最適です。

  • zustand:

    Zustandは、シンプルな状態管理が必要な小規模なアプリケーションに適しています。

  • jotai:

    Jotaiは、小規模なアプリケーションや、状態管理がシンプルな場合に最適です。

  • mobx-react-lite:

    MobX-React-Liteは、リアクティブなデータフローが必要なアプリケーションに適しています。

  • react-query:

    React Queryは、サーバーからのデータを頻繁に取得する必要があるアプリケーションに最適です。

  • recoil:

    Recoilは、複雑な状態管理が必要なReactアプリケーションに適しています。

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

    Reduxは、大規模なアプリケーションや複雑な状態管理が必要な場合に最適です。アプリケーションの状態を一元管理し、予測可能な状態変化を提供します。

  • zustand:

    Zustandは、シンプルで軽量な状態管理を求める場合に適しています。APIが簡潔で、必要な機能だけを持つため、学習コストが低いです。

  • jotai:

    Jotaiは、シンプルで軽量な状態管理を求める場合に最適です。原子状態の概念を使用しており、必要な部分だけを再レンダリングするため、パフォーマンスが向上します。

  • mobx-react-lite:

    MobX-React-Liteは、リアクティブプログラミングを好む場合に適しています。状態の変更を自動的に追跡し、UIを効率的に更新します。

  • react-query:

    React Queryは、サーバーからのデータ取得やキャッシングを簡素化したい場合に最適です。データのフェッチング、キャッシング、更新を管理するための強力なツールを提供します。

  • recoil:

    Recoilは、ReactのコンテキストAPIを拡張したい場合に適しています。グローバルな状態管理を簡単に行え、コンポーネント間での状態の共有が容易です。

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