Read Me

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

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 debuggerarrow-up-right.

You can use Redux together with Reactarrow-up-right, 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 fill out this survey on what content is most important in a docs sitearrow-up-right. Thanks!

build statusarrow-up-right npm versionarrow-up-right npm downloadsarrow-up-right redux channel on discordarrow-up-right Changelog #187arrow-up-right

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:

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:

Finally, Mark Erikson is teaching a series of Redux workshops through Workshop.me. Check the workshop schedulearrow-up-right for upcoming dates and locations.

Help and Discussion

The #redux channelarrow-up-right of the Reactiflux Discord communityarrow-up-right 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!

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

Dan Abramov (author of Redux) wrote Redux while working on his React Europe talk called “Hot Reloading with Time Travel”arrow-up-right. 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.

Influences

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

Installation

To install the stable version:

This assumes you are using npmarrow-up-right as your package manager.

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

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

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.

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!

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

Getting Started with Reduxarrow-up-right is a video course consisting of 30 videos narrated by Dan Abramovarrow-up-right, 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.

“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!”arrow-up-right Sandrino Di Mattia

“Plowing through @dan_abramov 'Getting Started with Redux' - its amazing how much simpler concepts get with video.”arrow-up-right Chris Dhanaraj

“This video series on Redux by @dan_abramov on @eggheadio is spectacular!”arrow-up-right Eddie Zaneski

“Come for the name hype. Stay for the rock solid fundamentals. (Thanks, and great job @dan_abramov and @eggheadio!)”arrow-up-right Dan

“This series of videos on Redux by @dan_abramov is repeatedly blowing my mind - gunna do some serious refactoring”arrow-up-right Laurence Roberts

So, what are you waiting for?

Note: If you enjoyed Dan's course, consider supporting Egghead by buying a subscriptionarrow-up-right. 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 Egghead instructorsarrow-up-right are also open source library authors, so buying a subscription is a nice way to thank them for the work that they've done.

Building React Applications with Idiomatic Redux

The Building React Applications with Idiomatic Reduxarrow-up-right 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.

Practical Redux course

Practical Reduxarrow-up-right is a paid interactive course by Redux co-maintainer Mark Eriksonarrow-up-right. 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:

  • 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!

The course is based on Mark's original free "Practical Redux" blog tutorial seriesarrow-up-right, but with updated and improved content.

Redux Fundamentals Workshop

Redux co-maintainer Mark Eriksonarrow-up-right has put together a Redux Fundamentals workshop, and slides are available herearrow-up-right. They cover:

  • 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

For PDF, ePub, and MOBI exports for offline reading, and instructions on how to create them, please see: paulkogel/redux-offline-docsarrow-up-right.

For Offline docs, please see: devdocsarrow-up-right

Examples

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

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 simplest-redux-examplearrow-up-right that uses Redux together with React and Browserify.

Testimonials

“Love what you're doing with Redux”arrow-up-right Jing Chen, creator of Flux

“I asked for comments on Redux in FB's internal JS discussion group, and it was universally praised. Really awesome work.”arrow-up-right Bill Fisher, author of Flux documentation

“It's cool that you are inventing a better Flux by not doing Flux at all.”arrow-up-right André Staltz, creator of Cycle

Thanks

Special thanks to Jamie Patonarrow-up-right for handing over the redux NPM package name.

You can find the official logo on GitHubarrow-up-right.

Change Log

This project adheres to Semantic Versioningarrow-up-right. Every release, along with the migration instructions, is documented on the GitHub Releasesarrow-up-right page.

Patrons

The work on Redux was funded by the communityarrow-up-right. Meet some of the outstanding companies that made it possible:

See the full list of Redux patrons, as well as the always-growing list of people and companies that use Reduxarrow-up-right.

License

MIT

Last updated