@reduxjs/toolkit vs zustand vs recoil vs jotai vs valtio
State Management Libraries
@reduxjs/toolkitzustandrecoiljotaivaltioSimilar Packages:

State Management Libraries

State management libraries are essential tools in modern web development that help manage the state of an application in a predictable and efficient manner. They provide a structured way to handle data flow, making it easier to maintain, debug, and scale applications. These libraries offer various approaches to state management, from centralized stores to more decentralized and reactive models, catering to different application needs and developer preferences.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
@reduxjs/toolkit011,1887.04 MB2654 months agoMIT
zustand057,63895 kB420 days agoMIT
recoil019,5072.21 MB3223 years agoMIT
jotai021,100526 kB1612 days agoMIT
valtio010,154101 kB4a month agoMIT

Feature Comparison: @reduxjs/toolkit vs zustand vs recoil vs jotai vs valtio

Reactivity Model

  • @reduxjs/toolkit:

    Redux Toolkit uses a centralized store with a predictable state model based on actions and reducers. State changes are explicit, making it easier to track and debug state transitions, but it may require more boilerplate code.

  • zustand:

    Zustand provides a simple store that allows for direct state manipulation. It uses hooks for reactivity, making it easy to access and update state without the complexity of a centralized store.

  • recoil:

    Recoil introduces a reactive model that allows atoms (units of state) and selectors (derived state) to be used together. This enables complex state dependencies and asynchronous queries, providing a more flexible approach to managing state in React applications.

  • jotai:

    Jotai employs an atomic state model where each piece of state is independent, allowing for fine-grained updates. This leads to more efficient re-renders, as only the components that depend on a specific atom will re-render when that atom changes.

  • valtio:

    Valtio uses JavaScript proxies to create a reactive state management solution. This means that state changes are automatically tracked, and components that depend on the state will re-render without needing to explicitly manage subscriptions or updates.

Learning Curve

  • @reduxjs/toolkit:

    Redux Toolkit has a steeper learning curve due to its concepts of actions, reducers, and middleware. However, it simplifies many of the complexities of Redux, making it more approachable than traditional Redux.

  • zustand:

    Zustand has a low learning curve, focusing on simplicity and minimalism. It is easy to set up and use, making it a great choice for developers who want to manage state without the overhead of more complex libraries.

  • recoil:

    Recoil is designed to be intuitive for React developers, leveraging familiar React concepts. Its learning curve is moderate, as it introduces new concepts like atoms and selectors but remains accessible for those with React experience.

  • jotai:

    Jotai has a gentle learning curve, especially for those familiar with React hooks. Its atomic approach allows developers to start small and scale their state management as needed without overwhelming complexity.

  • valtio:

    Valtio is very easy to learn, especially for those who are comfortable with JavaScript. Its proxy-based approach requires minimal setup and is straightforward to implement, making it ideal for quick prototyping.

Performance

  • @reduxjs/toolkit:

    Performance in Redux Toolkit can be optimized through techniques like memoization and selective rendering. However, the centralized nature may lead to performance bottlenecks if not managed properly, especially in large applications.

  • zustand:

    Zustand is lightweight and optimized for performance, allowing for fast state updates and minimal re-renders. Its simplicity contributes to efficient memory usage and responsiveness.

  • recoil:

    Recoil offers excellent performance with its ability to derive state and manage dependencies efficiently. Its architecture allows for selective re-renders, which can significantly improve performance in complex applications.

  • jotai:

    Jotai is designed for performance, as its atomic state updates ensure that only the components that depend on a specific atom re-render. This leads to efficient updates and minimal performance overhead.

  • valtio:

    Valtio's use of proxies allows for automatic reactivity without the need for manual subscriptions, leading to efficient updates and good performance. It is particularly effective for applications with frequent state changes.

Extensibility

  • @reduxjs/toolkit:

    Redux Toolkit is highly extensible, allowing developers to create custom middleware, enhancers, and integrate with various libraries. This makes it suitable for large applications that may require additional functionality.

  • zustand:

    Zustand is highly extensible, allowing developers to create custom stores and middleware. Its simple API makes it easy to add new features and integrate with other libraries.

  • recoil:

    Recoil is designed to be extensible with its atoms and selectors, allowing developers to create complex state management solutions. Its architecture supports custom hooks and integrations with other libraries.

  • jotai:

    Jotai is extensible through its atomic model, allowing developers to create custom atoms and hooks. This flexibility enables the addition of new features without disrupting existing state management.

  • valtio:

    Valtio is relatively simple, which limits its extensibility compared to others. However, its proxy-based model can be extended through custom functions and utilities for specific use cases.

Community and Ecosystem

  • @reduxjs/toolkit:

    Redux Toolkit benefits from a large community and a rich ecosystem of middleware, tools, and extensions. This support makes it easier to find resources and solutions for common challenges in state management.

  • zustand:

    Zustand has a vibrant community and is appreciated for its simplicity and performance. It is well-documented and has a growing number of plugins and integrations.

  • recoil:

    Recoil is backed by Facebook and has a rapidly growing community. Its integration with React makes it appealing, and it is supported by various resources and libraries.

  • jotai:

    Jotai has a growing community and is gaining popularity, but its ecosystem is not as extensive as Redux. However, it is well-documented and supported by a dedicated group of developers.

  • valtio:

    Valtio has a smaller community but is gaining traction due to its simplicity and effectiveness. It has good documentation and is suitable for developers looking for straightforward state management solutions.

How to Choose: @reduxjs/toolkit vs zustand vs recoil vs jotai vs valtio

  • @reduxjs/toolkit:

    Choose Redux Toolkit if you need a robust, scalable solution for managing complex state in large applications. It is ideal for applications that require a centralized store and predictable state transitions, especially when dealing with asynchronous operations.

  • zustand:

    Select Zustand for a lightweight and simple state management solution that focuses on ease of use and performance. It is ideal for small to medium-sized applications where you want to avoid the overhead of larger libraries while still maintaining a clear state structure.

  • recoil:

    Opt for Recoil if you are working with React and need a flexible state management solution that integrates seamlessly with React's concurrent features. It allows for derived state and asynchronous queries, making it suitable for applications with complex state dependencies.

  • jotai:

    Select Jotai for a minimalistic and atomic state management approach that allows for fine-grained reactivity. It is suitable for projects where you want to manage state in a more granular way without the boilerplate code often associated with larger libraries.

  • valtio:

    Choose Valtio for a simple and proxy-based state management solution that offers automatic reactivity. It is great for projects that require minimal setup and want to avoid the complexity of more traditional state management libraries.

README for @reduxjs/toolkit

Redux Toolkit

GitHub Workflow Status npm version npm downloads

The official, opinionated, batteries-included toolset for efficient Redux development

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:

An Existing App

Redux Toolkit is available as a package on NPM for use with a module bundler or in a Node application:

# NPM
npm install @reduxjs/toolkit

# Yarn
yarn add @reduxjs/toolkit

The package includes a precompiled ESM build that can be used as a <script type="module"> tag directly in the browser.

Documentation

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.

The Redux core docs at https://redux.js.org includes the full Redux tutorials, as well usage guides on general Redux patterns.

Purpose

The Redux Toolkit package is intended to be the standard way to write Redux logic. It was originally created to help address three common concerns about Redux:

  • "Configuring a Redux store is too complicated"
  • "I have to add a lot of packages to get Redux to do anything useful"
  • "Redux requires too much boilerplate code"

We can't solve every use case, but in the spirit of create-react-app, we can try to provide some tools that abstract over the setup process and handle the most common use cases, as well as include some useful utilities that will let the user simplify their application code.

Because of that, this package is deliberately limited in scope. It does not address concepts like "reusable encapsulated Redux modules", folder or file structures, managing entity relationships in the store, and so on.

Redux Toolkit also includes a powerful data fetching and caching capability that we've dubbed "RTK Query". It's included in the package as a separate set of entry points. It's optional, but can eliminate the need to hand-write data fetching logic yourself.

What's Included

Redux Toolkit includes these APIs:

  • configureStore(): wraps createStore to provide simplified configuration options and good defaults. It can automatically combine your slice reducers, add whatever Redux middleware you supply, includes redux-thunk by default, and enables use of the Redux DevTools Extension.
  • createReducer(): lets you supply a lookup table of action types to case reducer functions, rather than writing switch statements. In addition, it automatically uses the immer library to let you write simpler immutable updates with normal mutative code, like state.todos[3].completed = true.
  • createAction(): generates an action creator function for the given action type string. The function itself has toString() defined, so that it can be used in place of the type constant.
  • createSlice(): combines createReducer() + createAction(). Accepts an object of reducer functions, a slice name, and an initial state value, and automatically generates a slice reducer with corresponding action creators and action types.
  • combineSlices(): combines multiple slices into a single reducer, and allows "lazy loading" of slices after initialisation.
  • createListenerMiddleware(): lets you define "listener" entries that contain an "effect" callback with additional logic, and a way to specify when that callback should run based on dispatched actions or state changes. A lightweight alternative to Redux async middleware like sagas and observables.
  • createAsyncThunk(): accepts an action type string and a function that returns a promise, and generates a thunk that dispatches pending/resolved/rejected action types based on that promise
  • createEntityAdapter(): generates a set of reusable reducers and selectors to manage normalized data in the store
  • The createSelector() utility from the Reselect library, re-exported for ease of use.

For details, see the Redux Toolkit API Reference section in the docs.

RTK Query

RTK Query is provided as an optional addon within the @reduxjs/toolkit package. It is purpose-built to solve the use case of data fetching and caching, supplying a compact, but powerful toolset to define an API interface layer for your app. It is intended to simplify common cases for loading data in a web application, eliminating the need to hand-write data fetching & caching logic yourself.

RTK Query is built on top of the Redux Toolkit core for its implementation, using Redux internally for its architecture. Although knowledge of Redux and RTK are not required to use RTK Query, you should explore all of the additional global store management capabilities they provide, as well as installing the Redux DevTools browser extension, which works flawlessly with RTK Query to traverse and replay a timeline of your request & cache behavior.

RTK Query is included within the installation of the core Redux Toolkit package. It is available via either of the two entry points below:

import { createApi } from '@reduxjs/toolkit/query'

/* React-specific entry point that automatically generates
   hooks corresponding to the defined endpoints */
import { createApi } from '@reduxjs/toolkit/query/react'

What's included

RTK Query includes these APIs:

  • createApi(): The core of RTK Query's functionality. It allows you to define a set of endpoints describe how to retrieve data from a series of endpoints, including configuration of how to fetch and transform that data. In most cases, you should use this once per app, with "one API slice per base URL" as a rule of thumb.
  • fetchBaseQuery(): A small wrapper around fetch that aims to simplify requests. Intended as the recommended baseQuery to be used in createApi for the majority of users.
  • <ApiProvider />: Can be used as a Provider if you do not already have a Redux store.
  • setupListeners(): A utility used to enable refetchOnMount and refetchOnReconnect behaviors.

See the RTK Query Overview page for more details on what RTK Query is, what problems it solves, and how to use it.

Contributing

Please refer to our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to Redux Toolkit.