Redux
  • Read Me
  • Introduction
    • Motivation
    • Core Concepts
    • Three Principles
    • Prior Art
    • Learning Resources
    • Ecosystem
    • Examples
  • Basics
    • Actions
    • Reducers
    • Store
    • Data Flow
    • Usage with React
    • Example: Todo List
  • Advanced
    • Async Actions
    • Async Flow
    • Middleware
    • Usage with React Router
    • Example: Reddit API
    • Next Steps
  • Recipes
    • Configuring Your Store
    • Migrating to Redux
    • Using Object Spread Operator
    • Reducing Boilerplate
    • Server Rendering
    • Writing Tests
    • Computing Derived Data
    • Implementing Undo History
    • Isolating Subapps
    • Structuring Reducers
      • Prerequisite Concepts
      • Basic Reducer Structure
      • Splitting Reducer Logic
      • Refactoring Reducers Example
      • Using combineReducers
      • Beyond combineReducers
      • Normalizing State Shape
      • Updating Normalized Data
      • Reusing Reducer Logic
      • Immutable Update Patterns
      • Initializing State
    • Using Immutable.JS with Redux
  • FAQ
    • General
    • Reducers
    • Organizing State
    • Store Setup
    • Actions
    • Immutable Data
    • Code Structure
    • Performance
    • Design Decisions
    • React Redux
    • Miscellaneous
  • Troubleshooting
  • Glossary
  • API Reference
    • createStore
    • Store
    • combineReducers
    • applyMiddleware
    • bindActionCreators
    • compose
  • Change Log
  • Patrons
  • Feedback
Powered by GitBook
On this page
  • Learn Redux
  • Just the Basics
  • Intermediate Concepts
  • Real-World Usage
  • Help and Discussion
  • Before Proceeding Further
  • Developer Experience
  • Influences
  • Installation
  • Complementary Packages
  • The Gist
  • Learn Redux from Its Authors
  • Redux Video Tutorials by Dan Abramov
  • Practical Redux course
  • Redux Fundamentals Workshop
  • Documentation
  • Examples
  • Testimonials
  • Thanks
  • Logo
  • Change Log
  • Patrons
  • License

Read Me

NextIntroduction

Last updated 7 years ago

Redux is a predictable state container for JavaScript apps. (Not to be confused with a WordPress framework – .)

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 .

You can use Redux together with , or with any other view library. It is tiny (2kB, including dependencies).

Note: We are currently planning a rewrite of the Redux docs. Please take some time to . Thanks!

Learn Redux

We have a variety of resources available to help you learn Redux, no matter what your background or learning style is.

Just the Basics

If you're brand new to Redux and want to understand the basic concepts, see:

  • The behind building Redux, the , and the .

  • The

  • Redux creator Dan Abramov's free on Egghead.io

  • Redux co-maintainer Mark Erikson's and

  • If you learn best by looking at code and playing with it, check out our list of , available as separate projects in the Redux repo, and also as interactive online examples on CodeSandbox.

  • The section of the . Here's a top list of our recommended tutorials:

    • Dave Ceddia's posts and are a great intro to the basics of Redux and how to use it with React, as is this post on .

    • Valentino Gagliardi's post is an excellent extended introduction to many aspects of using Redux.

    • The CSS Tricks article covers the Redux basics well.

    • This tutorial covers several aspects of Redux, including actions, reducers, usage with React, and middleware.

Intermediate Concepts

Once you've picked up the basics of working with actions, reducers, and the store, you may have questions about topics like working with asynchronous logic and AJAX requests, connecting a UI framework like React to your Redux store, and setting up an application to use Redux:

Real-World Usage

Going from a TodoMVC app to a real production application can be a big jump, but we've got plenty of resources to help:

Help and Discussion

Before Proceeding Further

Redux is a valuable tool for organizing your state, but you should also consider whether it's appropriate for your situation. Don't use Redux just because someone said you should - 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 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, see:

Developer Experience

Influences

Installation

To install the stable version:

npm install --save redux

Complementary Packages

npm install --save react-redux
npm install --save-dev redux-devtools

The Gist

The whole state of your app is stored in an object tree inside a single store. The only way to change the state tree is to emit an action, an object describing what happened. To specify how the actions transform the state tree, you write pure reducers.

That's it!

import { createStore } from 'redux'

/**
 * This is a reducer, a pure function with (state, action) => state signature.
 * It describes how an action transforms the state into the next state.
 *
 * The shape of the state is up to you: it can be a primitive, an array, an object,
 * or even an Immutable.js data structure. The only important part is that you should
 * not mutate the state object, but return a new object if the state changes.
 *
 * In this example, we use a `switch` statement and strings, but you can use a helper that
 * follows a different convention (such as function maps) if it makes sense for your
 * project.
 */
function counter(state = 0, action) {
  switch (action.type) {
    case 'INCREMENT':
      return state + 1
    case 'DECREMENT':
      return state - 1
    default:
      return state
  }
}

// Create a Redux store holding the state of your app.
// Its API is { subscribe, dispatch, getState }.
let store = createStore(counter)

// You can use subscribe() to update the UI in response to state changes.
// Normally you'd use a view binding library (e.g. React Redux) rather than subscribe() directly.
// However it can also be handy to persist the current state in the localStorage.

store.subscribe(() => console.log(store.getState()))

// The only way to mutate the internal state is to dispatch an action.
// The actions can be serialized, logged or stored and later replayed.
store.dispatch({ type: 'INCREMENT' })
// 1
store.dispatch({ type: 'INCREMENT' })
// 2
store.dispatch({ type: 'DECREMENT' })
// 1

Instead of mutating the state directly, you specify the mutations you want to happen with plain objects called actions. Then you write a special function called a reducer to decide how every action transforms the entire application's state.

If you're coming from Flux, there is a single important difference you need to understand. Redux doesn't have a Dispatcher or support many stores. Instead, there is just a single store with a single root reducing function. As your app grows, instead of adding stores, you split the root reducer into smaller reducers independently operating on the different parts of the state tree. This is exactly like how there is just one root component in a React app, but it is composed out of many small components.

This architecture might seem like an overkill for a counter app, but the beauty of this pattern is how well it scales to large and complex apps. It also enables very powerful developer tools, because it is possible to trace every mutation to the action that caused it. You can record user sessions and reproduce them just by replaying every action.

Learn Redux from Its Authors

Redux Video Tutorials by Dan Abramov

Getting Started with Redux

So, what are you waiting for?

Building React Applications with Idiomatic Redux

Practical Redux course

  • Adding Redux to a new Create-React-App project and configuring Hot Module Replacement for faster development

  • Controlling your UI behavior with Redux

  • Using the Redux-ORM library to manage relational data in your Redux store

  • Building a master/detail view to display and edit data

  • Writing custom advanced Redux reducer logic to solve specific problems

  • Optimizing performance of Redux-connected form inputs

And much more!

Redux Fundamentals Workshop

  • The history and purpose of Redux

  • Reducers and actions, and working with a Redux store

  • Using Redux with React

  • Using and writing Redux middleware

  • Working with AJAX calls and other side effects

  • Unit testing Redux apps

  • Real-world Redux app structure and development

Documentation

Examples

Almost all examples have a corresponding CodeSandbox sandbox. This is an interactive version of the code that you can play with online.

Testimonials

Thanks

Logo

Change Log

Patrons

License

MIT

The covers working with async logic, middleware, routing.

The Redux docs page points to recommended articles on a variety of Redux-related topics.

Sophie DeBenedetto's 8-part series shows how to put together a basic CRUD app from scratch.

Redux creator Dan Abramov's builds on his first video series and covers topics like middleware, routing, and persistence.

The answers many common questions about how to use Redux, and the has information on handling derived data, testing, structuring reducer logic, and reducing boilerplate.

Redux co-maintainer Mark Erikson's demonstrates real-world intermediate and advanced techniques for working with React and Redux (also available as ).

The has categorized articles on working with , , , and more.

Our community has created thousands of Redux-related libraries, addons, and tools. The lists our recommendations, and there's a complete listing available in the .

If you're looking to learn from actual application codebases, the addons catalog also has a list of .

Finally, Mark Erikson is teaching a series of . Check the for upcoming dates and locations.

The of the 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 - come join us!

Dan Abramov (author of Redux) wrote Redux while working on his React Europe talk called . His goal was to create a state management library with a minimal API but completely predictable behavior. Redux makes it possible to implement logging, hot reloading, time travel, universal apps, record and replay, without any buy-in from the developer.

Redux evolves the ideas of , but avoids its complexity by taking cues from . Even if you haven't used Flux or Elm, Redux only takes a few minutes to get started with.

This assumes you are using as your package manager.

If you're not, you can , download them, or point your package manager to them.

Most commonly, people consume Redux as a collection of modules. These modules are what you get when you import redux in a , , or a Node environment. If you like to live on the edge and use , 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 builds in the . 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 on the page, or . 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 . You don't need to use Babel or a module bundler to .

Most likely, you'll also need and .

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

is a video course consisting of 30 videos narrated by , author of Redux. It is designed to complement the “Basics” part of the docs while bringing additional insights about immutability, testing, Redux best practices, and using Redux with React. This course is free and will always be.

Sandrino Di Mattia

Chris Dhanaraj

Eddie Zaneski

Dan

Laurence Roberts

Note: If you enjoyed Dan's course, consider supporting Egghead by . Subscribers have access to the source code of every example in my videos and tons of advanced lessons on other topics, including JavaScript in depth, React, Angular, and more. Many are also open source library authors, so buying a subscription is a nice way to thank them for the work that they've done.

The course is a second free video series by Dan Abramov. It picks up where the first series left off, and covers practical production ready techniques for building your React and Redux applications: advanced state management, middleware, React Router integration, and other common problems you are likely to encounter while building applications for your clients and customers. As with the first series, this course will always be free.

is a paid interactive course by Redux co-maintainer . The course is designed to show how to apply the basic concepts of Redux to building something larger than a TodoMVC application. It includes real-world topics like:

The course is based on Mark's original free , but with updated and improved content.

Redux co-maintainer has put together a . They cover:

For PDF, ePub, and MOBI exports for offline reading, and instructions on how to create them, please see: .

For Offline docs, please see:

:

: |

: |

: |

:

: |

: |

: |

: |

:

: |

If you're new to the NPM ecosystem and have troubles getting a project up and running, or aren't sure where to paste the gist above, check out that uses Redux together with React and Browserify.

Jing Chen, creator of Flux

Bill Fisher, author of Flux documentation

André Staltz, creator of Cycle

for a great intro to modeling state updates with reducers;

for blowing my mind;

for convincing me that re-evaluation should “just work”;

for Hot Module Replacement;

for teaching me to approach Flux without boilerplate or singletons;

for a proof of concept of hot reloadable Stores;

for proving this architecture can be performant;

for popularizing the idea of a single state atom;

for showing how often a function is the best tool;

for the pragmatic innovation.

Special thanks to for handing over the redux NPM package name.

You can find the official logo .

This project adheres to . Every release, along with the migration instructions, is documented on the GitHub page.

The work on Redux was . Meet some of the outstanding companies that made it possible:

, as well as the always-growing list of .

"Advanced" docs section
"Learning Resources"
Building a Simple CRUD App with React + Redux
free "Building React Applications with Idiomatic Redux" video series
Redux FAQ
"Recipes" docs section
"Practical Redux" tutorial series
an interactive course on Educative.io
React/Redux links list
reducers and selectors
managing side effects
Redux architecture and best practices
"Ecosystem" docs page
Redux addons catalog
purpose-built examples and real-world applications
#redux channel
Reactiflux Discord community
You Might Not Need Redux
The Tao of Redux, Part 1 - Implementation and Intent
The Tao of Redux, Part 2 - Practice and Philosophy
Redux FAQ
“Hot Reloading with Time Travel”
Flux
Elm
npm
access these files on unpkg
CommonJS
Webpack
Browserify
Rollup
UMD
dist folder
<script> tag
tell Bower to install it
any modern browser
get started with Redux
the React bindings
the developer tools
Webpack
Browserify
Getting Started with Redux
Dan Abramov
“Great course on egghead.io by @dan_abramov - instead of just showing you how to use #redux, it also shows how and why redux was built!”
“Plowing through @dan_abramov 'Getting Started with Redux' - its amazing how much simpler concepts get with video.”
“This video series on Redux by @dan_abramov on @eggheadio is spectacular!”
“Come for the name hype. Stay for the rock solid fundamentals. (Thanks, and great job @dan_abramov and @eggheadio!)”
“This series of videos on Redux by @dan_abramov is repeatedly blowing my mind - gunna do some serious refactoring”
Watch the free "Getting Started with Redux" video series
buying a subscription
Egghead instructors
Building React Applications with Idiomatic Redux
Watch the free "Idiomatic Redux" video series
Practical Redux
Mark Erikson
"Practical Redux" blog tutorial series
Mark Erikson
Redux Fundamentals workshop, and slides are available here
Introduction
Basics
Advanced
Recipes
FAQ
Troubleshooting
Glossary
API Reference
paulkogel/redux-offline-docs
devdocs
Counter Vanilla
Source
Counter
Source
Sandbox
Todos
Source
Sandbox
Todos with Undo
Source
Sandbox
Todos w/ Flow
Source
TodoMVC
Source
Sandbox
Shopping Cart
Source
Sandbox
Tree View
Source
Sandbox
Async
Source
Sandbox
Universal
Source
Real World
Source
Sandbox
simplest-redux-example
“Love what you're doing with Redux”
“I asked for comments on Redux in FB's internal JS discussion group, and it was universally praised. Really awesome work.”
“It's cool that you are inventing a better Flux by not doing Flux at all.”
The Elm Architecture
Turning the database inside-out
Developing ClojureScript with Figwheel
Webpack
Flummox
disto
NuclearJS
Om
Cycle
React
Jamie Paton
on GitHub
Semantic Versioning
Releases
funded by the community
Webflow
Ximedes
See the full list of Redux patrons
people and companies that use Redux
workshop schedule
Redux workshops through Workshop.me
Redux Framework
live code editing combined with a time traveling debugger
React
fill out this survey on what content is most important in a docs site
Motivation
Core Concepts
Three Principles
basic tutorial in the Redux docs
"Getting Started with Redux" video series
"Redux Fundamentals" slideshow
list of suggested resources for learning Redux
Redux example applications
Redux Tutorials
React/Redux links list
What Does Redux Do? (and when should you use it?)
How Redux Works: A Counter-Example
React and Redux: An Introduction
React Redux Tutorial for Beginners: Learning Redux in 2018
Leveling Up with React: Redux
DevGuides: Introduction to Redux
build status
npm version
npm downloads
redux channel on discord
Changelog #187