Redux Docs

Installation

Redux Toolkit#arrow-up-right

Redux Toolkit includes the Redux core, as well as other key packages we feel are essential for building Redux applications (such as Redux Thunk and Reselect).

It's available as a package on NPM for use with a module bundler or in a Node application:

# NPMnpm install @reduxjs/toolkit
# Yarnyarn add @reduxjs/toolkit

Copy

It's also available as a UMD build, which can be loaded from the dist folder on unpkgarrow-up-right. The UMD builds make Redux Toolkit available as a window.RTK global variable.

Redux Core#arrow-up-right

To install the stable version:

# NPMnpm install redux
# Yarnyarn add redux

Copy

If you're not, you can access these files on unpkgarrow-up-right, download them, or point your package manager to them.

Most commonly, people consume Redux as a collection of CommonJSarrow-up-right modules. These modules are what you get when you import redux in a Webpackarrow-up-right, Browserifyarrow-up-right, or a Node environment. If you like to live on the edge and use Rolluparrow-up-right, we support that as well.

If you don't use a module bundler, it's also fine. The redux npm package includes precompiled production and development UMDarrow-up-right builds in the dist folderarrow-up-right. They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments. For example, you can drop a UMD build as a <script> tagarrow-up-right on the page, or tell Bower to install itarrow-up-right. The UMD builds make Redux available as a window.Redux global variable.

The Redux source code is written in ES2015 but we precompile both CommonJS and UMD builds to ES5 so they work in any modern browserarrow-up-right. You don't need to use Babel or a module bundler to get started with Reduxarrow-up-right.

Complementary Packages#arrow-up-right

Most likely, you'll also need the React bindingsarrow-up-right and the developer toolsarrow-up-right.

Copy

Note that unlike Redux itself, many packages in the Redux ecosystem don't provide UMD builds, so we recommend using CommonJS module bundlers like Webpackarrow-up-right and Browserifyarrow-up-right for the most comfortable development experience.

Create a React Redux App#arrow-up-right

The recommended way to start new apps with React and Redux is by using the official Redux+JS templatearrow-up-right or Redux+TS templatearrow-up-right for Create React Apparrow-up-right, which takes advantage of Redux Toolkitarrow-up-right and React Redux's integration with React components.

Core Concepts

Imagine your app’s state is described as a plain object. For example, the state of a todo app might look like this:

Copy

This object is like a “model” except that there are no setters. This is so that different parts of the code can’t change the state arbitrarily, causing hard-to-reproduce bugs.

To change something in the state, you need to dispatch an action. An action is a plain JavaScript object (notice how we don’t introduce any magic?) that describes what happened. Here are a few example actions:

Copy

Enforcing that every change is described as an action lets us have a clear understanding of what’s going on in the app. If something changed, we know why it changed. Actions are like breadcrumbs of what has happened. Finally, to tie state and actions together, we write a function called a reducer. Again, nothing magical about it—it’s just a function that takes state and action as arguments, and returns the next state of the app. It would be hard to write such a function for a big app, so we write smaller functions managing parts of the state:

Copy

And we write another reducer that manages the complete state of our app by calling those two reducers for the corresponding state keys:

Copy

This is basically the whole idea of Redux. Note that we haven’t used any Redux APIs. It comes with a few utilities to facilitate this pattern, but the main idea is that you describe how your state is updated over time in response to action objects, and 90% of the code you write is just plain JavaScript, with no use of Redux itself, its APIs, or any magic.

Ecosystem

Redux is a tiny library, but its contracts and APIs are carefully chosen to spawn an ecosystem of tools and extensions, and the community has created a wide variety of helpful addons, libraries, and tools. You don't need to use any of these addons to use Redux, but they can help make it easier to implement features and solve problems in your application.

For an extensive catalog of libraries, addons, and tools related to Redux, check out the Redux Ecosystem Linksarrow-up-right list. Also, the React/Redux Linksarrow-up-right list contains tutorials and other useful resources for anyone learning React or Redux.

This page lists some of the Redux-related addons that the Redux maintainers have vetted personally, or that have shown widespread adoption in the community. Don't let this discourage you from trying the rest of them! The ecosystem is growing too fast, and we have a limited time to look at everything. Consider these the “staff picks”, and don't hesitate to submit a PR if you've built something wonderful with Redux.

Table of Contents#arrow-up-right

Library Integration and Bindings#arrow-up-right

reduxjs/react-reduxarrow-up-right The official React bindings for Redux, maintained by the Redux team

angular-redux/ng-reduxarrow-up-right Angular 1 bindings for Redux

ember-redux/ember-reduxarrow-up-right Ember bindings for Redux

glimmer-redux/glimmer-reduxarrow-up-right Redux bindings for Ember's Glimmer component engine

tur-nr/polymer-reduxarrow-up-right Redux bindings for Polymer

lastmjs/redux-store-elementarrow-up-right Redux bindings for custom elements

Reducer Combination#

ryo33/combineSectionReducersarrow-up-right An expanded version of combineReducers, which allows passing state as a third argument to all slice reducers.

KodersLab/topologically-combine-reducersarrow-up-right A combineReducers variation that allows defining cross-slice dependencies for ordering and data passing

Copy

Reducer Composition#

acdlite/reduce-reducersarrow-up-right Provides sequential composition of reducers at the same level

Copy

mhelmer/redux-xformsarrow-up-right A collection of composable reducer transformers

Copy

adrienjt/redux-data-structuresarrow-up-right Reducer factory functions for common data structures: counters, maps, lists (queues, stacks), sets

Copy

Higher-Order Reducers#

omnidan/redux-undoarrow-up-right Effortless undo/redo and action history for your reducers

omnidan/redux-ignorearrow-up-right Ignore redux actions by array or filter function

omnidan/redux-recyclearrow-up-right Reset the redux state on certain actions

ForbesLindesay/redux-optimistarrow-up-right A reducer enhancer to enable type-agnostic optimistic updates

reduxactions/redux-actionsarrow-up-right Flux Standard Action utilities for Redux

Copy

BerkeleyTrue/redux-create-typesarrow-up-right Creates standard and async action types based on namespaces

Copy

maxhallinan/kreighterarrow-up-right Generates action creators based on types and expected fields

Copy

reduxjs/reselectarrow-up-right Creates composable memoized selector functions for efficiently deriving data from the store state

Copy

paularmstrong/normalizrarrow-up-right Normalizes nested JSON according to a schema

Copy

planttheidea/selectoratorarrow-up-right Abstractions over Reselect for common selector use cases

Copy

Change Subscriptions#

jprichardson/redux-watcharrow-up-right Watch for state changes based on key paths or selectors

Copy

ashaffer/redux-subscribearrow-up-right Centralized subscriptions to state changes based on paths

Copy

Batching#

tappleby/redux-batched-subscribearrow-up-right Store enhancer that can debounce subscription notifications

Copy

manaflair/redux-batcharrow-up-right Store enhancer that allows dispatching arrays of actions

Copy

laysent/redux-batch-actions-enhancerarrow-up-right Store enhancer that accepts batched actions

Copy

tshelburne/redux-batched-actionsarrow-up-right Higher-order reducer that handles batched actions

Copy

Persistence#

rt2zz/redux-persistarrow-up-right Persist and rehydrate a Redux store, with many extensible options

Copy

react-stack/redux-storagearrow-up-right Persistence layer for Redux with flexible backends

Copy

redux-offline/redux-offlinearrow-up-right Persistent store for Offline-First apps, with support for optimistic UIs

Copy

Immutable Data#arrow-up-right

ImmerJS/immerarrow-up-right Immutable updates with normal mutative code, using Proxies

Copy

Side Effects#arrow-up-right

Widely Used#

gaearon/redux-thunkarrow-up-right Dispatch functions, which are called and given dispatch and getState as parameters. This acts as a loophole for AJAX calls and other async behavior.

Best for: getting started, simple async and complex synchronous logic.

Copy

redux-saga/redux-sagaarrow-up-right Handle async logic using synchronous-looking generator functions. Sagas return descriptions of effects, which are executed by the saga middleware, and act like "background threads" for JS applications.

Best for: complex async logic, decoupled workflows

Copy

redux-observable/redux-observablearrow-up-right

Handle async logic using RxJS observable chains called "epics". Compose and cancel async actions to create side effects and more.

Best for: complex async logic, decoupled workflows

Copy

redux-loop/redux-looparrow-up-right

A port of the Elm Architecture to Redux that allows you to sequence your effects naturally and purely by returning them from your reducers. Reducers now return both a state value and a side effect description.

Best for: trying to be as much like Elm as possible in Redux+JS

Copy

jeffbski/redux-logicarrow-up-right

Side effects lib built with observables, but allows use of callbacks, promises, async/await, or observables. Provides declarative processing of actions.

Best for: very decoupled async logic

Copy

Promises#

acdlite/redux-promisearrow-up-right Dispatch promises as action payloads, and have FSA-compliant actions dispatched as the promise resolves or rejects.

Copy

lelandrichardson/redux-packarrow-up-right Sensible, declarative, convention-based promise handling that guides users in a good direction without exposing the full power of dispatch.

Copy

Middleware#arrow-up-right

Networks and Sockets#

svrcekmichal/redux-axios-middlewarearrow-up-right Fetches data with Axios and dispatches start/success/fail actions

Copy

agraboso/redux-api-middlewarearrow-up-right Reads API call actions, fetches, and dispatches FSAs

Copy

itaylor/redux-socket.ioarrow-up-right An opinionated connector between socket.io and redux.

Copy

tiberiuc/redux-react-firebasearrow-up-right Integration between Firebase, React, and Redux

Async Behavior#

rt2zz/redux-action-bufferarrow-up-right Buffers all actions into a queue until a breaker condition is met, at which point the queue is released

wyze/redux-debouncearrow-up-right FSA-compliant middleware for Redux to debounce actions.

mathieudutour/redux-queue-offlinearrow-up-right Queue actions when offline and dispatch them when getting back online.

Analytics#

rangle/redux-beaconarrow-up-right Integrates with any analytics services, can track while offline, and decouples analytics logic from app logic

markdalgleish/redux-analyticsarrow-up-right Watches for Flux Standard Actions with meta analytics values and processes them

Entities and Collections#arrow-up-right

tommikaikkonen/redux-ormarrow-up-right A simple immutable ORM to manage relational data in your Redux store.

Versent/redux-crudarrow-up-right Convention-based actions and reducers for CRUD logic

kwelch/entities-reducerarrow-up-right A higher-order reducer that handles data from Normalizr

amplitude/redux-queryarrow-up-right Declare colocated data dependencies with your components, run queries when components mount, perform optimistic updates, and trigger server changes with Redux actions.

cantierecreativo/redux-beesarrow-up-right Declarative JSON-API interaction that normalizes data, with a React HOC that can run queries

GetAmbassador/redux-clerkarrow-up-right Async CRUD handling with normalization, optimistic updates, sync/async action creators, selectors, and an extendable reducer.

shoutem/redux-ioarrow-up-right JSON-API abstraction with async CRUD, normalization, optimistic updates, caching, data status, and error handling.

jmeas/redux-resourcearrow-up-right A tiny but powerful system for managing 'resources': data that is persisted to remote servers.

Component State and Encapsulation#arrow-up-right

threepointone/redux-react-localarrow-up-right Local component state in Redux, with handling for component actions

Copy

epeli/lean-reduxarrow-up-right Makes component state in Redux as easy as setState

Copy

DataDog/redux-doghousearrow-up-right Aims to make reusable components easier to build with Redux by scoping actions and reducers to a particular instance of a component.

Copy

Debuggers and Viewers#

reduxjs/redux-devtoolsarrow-up-right

Dan Abramov's original Redux DevTools implementation, built for in-app display of state and time-travel debugging

zalmoxisus/redux-devtools-extensionarrow-up-right

Mihail Diordiev's browser extension, which bundles multiple state monitor views and adds integration with the browser's own dev tools

infinitered/reactotronarrow-up-right

A cross-platform Electron app for inspecting React and React Native apps, including app state, API requests, perf, errors, sagas, and action dispatching.

DevTools Monitors#

Log Monitorarrow-up-right The default monitor for Redux DevTools with a tree view

Dock Monitorarrow-up-right A resizable and movable dock for Redux DevTools monitors

Slider Monitorarrow-up-right A custom monitor for Redux DevTools to replay recorded Redux actions

Diff Monitorarrow-up-right A monitor for Redux DevTools that diffs the Redux store mutations between actions

Filterable Log Monitorarrow-up-right Filterable tree view monitor for Redux DevTools

Filter Actionsarrow-up-right Redux DevTools composable monitor with the ability to filter actions

Logging#

evgenyrodionov/redux-loggerarrow-up-right Logging middleware that shows actions, states, and diffs

inakianduaga/redux-state-historyarrow-up-right Enhancer that provides time-travel and efficient action recording capabilities, including import/export of action logs and action playback.

joshwcomeau/redux-vcrarrow-up-right Record and replay user sessions in real-time

socialtables/redux-unhandled-actionarrow-up-right Warns about actions that produced no state changes in development

Mutation Detection#

leoasis/redux-immutable-state-invariantarrow-up-right Middleware that throws an error when you try to mutate your state either inside a dispatch or between dispatches.

flexport/mutation-sentinelarrow-up-right Helps you deeply detect mutations at runtime and enforce immutability in your codebase.

mmahalwy/redux-pure-connectarrow-up-right Check and log whether react-redux's connect method is passed mapState functions that create impure props.

arnaudbenard/redux-mock-storearrow-up-right A mock store that saves dispatched actions in an array for assertions

Workable/redux-test-beltarrow-up-right Extends the store API to make it easier assert, isolate, and manipulate the store

conorhastings/redux-test-recorderarrow-up-right Middleware to automatically generate reducers tests based on actions in the app

wix/redux-testkitarrow-up-right Complete and opinionated testkit for testing Redux projects (reducers, selectors, actions, thunks)

jfairbank/redux-saga-test-planarrow-up-right Makes integration and unit testing of sagas a breeze

supasate/connected-react-routerarrow-up-right Synchronize React Router 4 state with your Redux store.

faceyspacey/redux-first-routerarrow-up-right Seamless Redux-first routing. Think of your app in states, not routes, not components, while keeping the address bar in sync. Everything is state. Connect your components and just dispatch flux standard actions.

erikras/redux-formarrow-up-right A full-featured library to enable a React HTML form to store its state in Redux.

davidkpiano/react-redux-formarrow-up-right React Redux Form is a collection of reducer creators and action creators that make implementing even the most complex and custom forms with React and Redux simple and performant.

Higher-Level Abstractions#arrow-up-right

keajs/keaarrow-up-right An abstraction over Redux, Redux-Saga and Reselect. Provides a framework for your app’s actions, reducers, selectors and sagas. It empowers Redux, making it as simple to use as setState. It reduces boilerplate and redundancy, while retaining composability.

TheComfyChair/redux-sccarrow-up-right Takes a defined structure and uses 'behaviors' to create a set of actions, reducer responses and selectors.

Bloomca/redux-tilesarrow-up-right Provides minimal abstraction on top of Redux, to allow easy composability, easy async requests, and sane testability.

Community Conventions#arrow-up-right

Flux Standard Actionarrow-up-right A human-friendly standard for Flux action objects

Canonical Reducer Compositionarrow-up-right An opinionated standard for nested reducer composition

Ducks: Redux Reducer Bundlesarrow-up-right A proposal for bundling reducers, action types and actions

Examples

Redux is distributed with a few examples in its source codearrow-up-right. Most of these examples are also on CodeSandboxarrow-up-right, an online editor that lets you play with the examples online.

Counter Vanilla#arrow-up-right

Run the Counter Vanillaarrow-up-right example:

Copy

Or check out the sandboxarrow-up-right:

It does not require a build system or a view framework and exists to show the raw Redux API used with ES5.

Run the Counterarrow-up-right example:

Copy

Or check out the sandboxarrow-up-right:

This is the most basic example of using Redux together with React. For simplicity, it re-renders the React component manually when the store changes. In real projects, you will likely want to use the highly performant React Reduxarrow-up-right bindings instead.

This example includes tests.

Run the Todosarrow-up-right example:

Copy

Or check out the sandboxarrow-up-right:

This is the best example to get a deeper understanding of how the state updates work together with components in Redux. It shows how reducers can delegate handling actions to other reducers, and how you can use React Reduxarrow-up-right to generate container components from your presentational components.

This example includes tests.

Todos with Undo#arrow-up-right

Run the Todos with Undoarrow-up-right example:

Copy

Or check out the sandboxarrow-up-right:

This is a variation on the previous example. It is almost identical, but additionally shows how wrapping your reducer with Redux Undoarrow-up-right lets you add a Undo/Redo functionality to your app with a few lines of code.

Run the TodoMVCarrow-up-right example:

Copy

Or check out the sandboxarrow-up-right:

This is the classical TodoMVCarrow-up-right example. It's here for the sake of comparison, but it covers the same points as the Todos example.

This example includes tests.

Shopping Cart#arrow-up-right

Run the Shopping Cartarrow-up-right example:

Copy

Or check out the sandboxarrow-up-right:

This example shows important idiomatic Redux patterns that become important as your app grows. In particular, it shows how to store entities in a normalized way by their IDs, how to compose reducers on several levels, and how to define selectors alongside the reducers so the knowledge about the state shape is encapsulated. It also demonstrates logging with Redux Loggerarrow-up-right and conditional dispatching of actions with Redux Thunkarrow-up-right middleware.

Run the Tree Viewarrow-up-right example:

Copy

Or check out the sandboxarrow-up-right:

This example demonstrates rendering a deeply nested tree view and representing its state in a normalized form so it is easy to update from reducers. Good rendering performance is achieved by the container components granularly subscribing only to the tree nodes that they render.

This example includes tests.

Run the Asyncarrow-up-right example:

Copy

Or check out the sandboxarrow-up-right:

This example includes reading from an asynchronous API, fetching data in response to user input, showing loading indicators, caching the response, and invalidating the cache. It uses Redux Thunkarrow-up-right middleware to encapsulate asynchronous side effects.

Run the Universalarrow-up-right example:

Copy

This is a basic demonstration of server renderingarrow-up-right with Redux and React. It shows how to prepare the initial store state on the server, and pass it down to the client so the client store can boot up from an existing state.

Real World#arrow-up-right

Run the Real Worldarrow-up-right example:

Copy

Or check out the sandboxarrow-up-right:

This is the most advanced example. It is dense by design. It covers keeping fetched entities in a normalized cache, implementing a custom middleware for API calls, rendering partially loaded data, pagination, caching responses, displaying error messages, and routing. Additionally, it includes Redux DevTools.

Last updated