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

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

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
redux16,880,36861,413290 kB462年前MIT
zustand12,662,33655,98894.3 kB34日前MIT
formik3,038,03534,351585 kB83123日前Apache-2.0
xstate2,503,58128,9862.19 MB1701ヶ月前MIT
mobx2,225,46028,1114.35 MB782ヶ月前MIT
jotai2,099,58520,798501 kB62日前MIT
react-query1,361,75547,6262.26 MB1353年前MIT
recoil500,03919,5622.21 MB3233年前MIT
機能比較: redux vs zustand vs formik vs xstate vs mobx vs jotai vs react-query vs recoil

学習曲線

  • redux:

    Reduxは、ミドルウェアやストアの概念を理解する必要があり、学習曲線はやや急ですが、強力な状態管理が可能です。

  • zustand:

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

  • formik:

    Formikは、フォーム管理に特化しているため、フォームのバリデーションや状態管理の概念を理解していれば比較的簡単に学べます。

  • xstate:

    XStateは、状態マシンの概念を理解する必要がありますが、視覚的に状態遷移を管理できるため、学習は価値があります。

  • mobx:

    MobXは、リアクティブプログラミングの概念を理解する必要がありますが、直感的なAPIにより、学習は比較的容易です。

  • jotai:

    Jotaiは、シンプルなAPIを持ち、状態管理の基本を理解していればすぐに使い始めることができます。

  • react-query:

    React Queryは、データフェッチングの概念を理解していればすぐに使えますが、キャッシングや更新の管理には少し慣れが必要です。

  • recoil:

    Recoilは、ReactのコンテキストAPIに似た構造を持っているため、Reactに慣れている開発者には学びやすいです。

パフォーマンス

  • redux:

    Reduxは、状態の予測可能性を高めるため、パフォーマンスが高いですが、複雑なアプリケーションではオーバーヘッドが発生することがあります。

  • zustand:

    Zustandは、軽量でシンプルなAPIを持ち、必要な状態のみを管理するため、パフォーマンスに優れています。

  • formik:

    Formikは、フォームの状態管理を効率的に行うため、パフォーマンスに優れていますが、非常に大規模なフォームではパフォーマンスが低下する可能性があります。

  • xstate:

    XStateは、状態遷移を明示的に管理するため、複雑な状態管理において高いパフォーマンスを発揮します。

  • mobx:

    MobXは、状態の変更を自動的に追跡するため、パフォーマンスが高く、リアクティブなアプローチが特徴です。

  • jotai:

    Jotaiは、必要な状態のみを管理するため、パフォーマンスが高く、特に小規模なアプリケーションに適しています。

  • react-query:

    React Queryは、データのキャッシングと更新を効率的に行うため、サーバーとの通信において高いパフォーマンスを発揮します。

  • recoil:

    Recoilは、状態のグローバル管理を提供し、パフォーマンスを最適化するための機能が豊富です。

設計原則

  • redux:

    Reduxは、状態の予測可能性と一貫性を重視した設計原則に基づいています。

  • zustand:

    Zustandは、シンプルで直感的なAPIを持ち、必要な状態のみを管理する設計が特徴です。

  • formik:

    Formikは、フォームの状態管理に特化しており、明確な設計原則に基づいています。

  • xstate:

    XStateは、状態遷移を明示的に定義することに重点を置いた設計原則を持っています。

  • mobx:

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

  • jotai:

    Jotaiは、原子ベースの状態管理を採用しており、シンプルで直感的な設計が特徴です。

  • react-query:

    React Queryは、サーバー状態の管理に特化しており、データのフェッチングとキャッシングに重点を置いています。

  • recoil:

    Recoilは、ReactのコンテキストAPIを拡張した設計で、状態のグローバル管理を提供します。

拡張性

  • redux:

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

  • zustand:

    Zustandは、シンプルなAPIを持ち、必要に応じて機能を拡張することができます。

  • formik:

    Formikは、カスタムバリデーションやフィールドコンポーネントを作成することで拡張性があります。

  • xstate:

    XStateは、状態マシンを定義することで、複雑な状態管理を拡張することができます。

  • mobx:

    MobXは、プラグインを使用して機能を拡張することができ、柔軟性があります。

  • jotai:

    Jotaiは、原子ベースのアプローチにより、状態の拡張が容易です。

  • react-query:

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

  • recoil:

    Recoilは、セレクタやアトムを使用して、状態管理の拡張が可能です。

一貫性

  • redux:

    Reduxは、状態の一貫性を高めるために、ストアとアクションの明確な構造を持っています。

  • zustand:

    Zustandは、シンプルなAPIを持ち、一貫した状態管理を提供します。

  • formik:

    Formikは、フォームの状態を一貫して管理するために設計されており、バリデーションやエラーメッセージの一貫性を保ちます。

  • xstate:

    XStateは、状態遷移を明示的に定義することで、一貫した状態管理を実現します。

  • mobx:

    MobXは、リアクティブなアプローチにより、状態の一貫性を保ちながらUIを更新します。

  • jotai:

    Jotaiは、原子ベースの状態管理により、一貫した状態管理を提供します。

  • react-query:

    React Queryは、データの取得とキャッシングを一貫して管理し、サーバー状態を簡単に扱えます。

  • recoil:

    Recoilは、状態のグローバル管理により、一貫したデータフローを提供します。

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

    大規模なアプリケーションでの状態管理が必要な場合、Reduxを選択してください。Reduxは、状態の予測可能性を高め、アプリケーションの状態を一元管理するための強力なツールです。

  • zustand:

    シンプルで直感的なAPIを求める場合、Zustandを選択してください。Zustandは、軽量で使いやすい状態管理を提供し、必要な状態のみを管理することができます。

  • formik:

    フォームの状態管理が必要な場合、Formikを選択してください。Formikは、フォームのバリデーションやエラーメッセージの管理を簡単に行うことができ、特に複雑なフォームに適しています。

  • xstate:

    状態遷移を明示的に管理したい場合、XStateを選択してください。XStateは、状態マシンを使用して、アプリケーションの状態遷移を視覚的に定義し、管理することができます。

  • mobx:

    リアクティブプログラミングを活用したい場合、MobXを選択してください。MobXは、状態の変更を自動的に追跡し、UIを効率的に更新するため、複雑な状態管理に適しています。

  • jotai:

    シンプルで軽量な状態管理を求める場合、Jotaiを選択してください。Jotaiは、原子ベースの状態管理を提供し、必要な状態のみを管理することで、パフォーマンスを向上させます。

  • react-query:

    サーバーからのデータフェッチングを簡素化したい場合、React Queryを選択してください。React Queryは、データの取得、キャッシング、更新を容易にし、サーバー状態の管理に特化しています。

  • recoil:

    ReactのコンテキストAPIを拡張したい場合、Recoilを選択してください。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