# actions

[![Redux Logo](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/official/d33wubrfki0l68.cloudfront.net/0834d0215db51e91525a25acf97433051f280f2f/c30f5/img/redux.svg)**Redux**](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/index.html)

[Getting Started](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/introduction/getting-started.html)[Tutorial](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/essentials/part-1-overview-concepts.html)[API](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/api/api-reference.html)[FAQ](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/faq.html)[Best Practices](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/style-guide/style-guide.html)[GitHub](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/official/github.com/reduxjs/redux.html)[Need help?](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/introduction/getting-started.html#help-and-discussion)

🌜

🌞

Search

[![Redux Logo](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/official/d33wubrfki0l68.cloudfront.net/0834d0215db51e91525a25acf97433051f280f2f/c30f5/img/redux.svg)**Redux**](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/index.html)

* [Introduction](#!)
  * [Getting Started with Redux](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/introduction/getting-started.html)
  * [Installation](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/introduction/installation.html)
  * [Core Concepts](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/introduction/core-concepts.html)
  * [Learning Resources](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/introduction/learning-resources.html)
  * [Ecosystem](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/introduction/ecosystem.html)
  * [Examples](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/introduction/examples.html)
* [Tutorials](#!)
  * [Tutorials Index](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/index.html)
  * [Quick Start](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/quick-start.html)
  * [TypeScript Quick Start](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/typescript-quick-start.html)
  * [Redux Essentials](#!)
    * [Redux Overview and Concepts](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/essentials/part-1-overview-concepts.html)
    * [Redux App Structure](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/essentials/part-2-app-structure.html)
    * [Basic Redux Data Flow](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/essentials/part-3-data-flow.html)
    * [Using Redux Data](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/essentials/part-4-using-data.html)
    * [Async Logic and Data Fetching](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/essentials/part-5-async-logic.html)
    * [Performance and Normalizing Data](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/essentials/part-6-performance-normalization.html)
  * [Redux Fundamentals](#!)
    * [Redux Overview](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/fundamentals/part-1-overview.html)
    * [Redux Concepts and Data Flow](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/fundamentals/part-2-concepts-data-flow.html)
    * [State, Actions, and Reducers](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/fundamentals/part-3-state-actions-reducers.html)
    * [Store](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/fundamentals/part-4-store.html)
    * [UI and React](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/fundamentals/part-5-ui-react.html)
    * [Async Logic and Data Fetching](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/fundamentals/part-6-async-logic.html)
    * [Standard Redux Patterns](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/fundamentals/part-7-standard-patterns.html)
    * [Modern Redux with Redux Toolkit](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/fundamentals/part-8-modern-redux.html)
* [Recipes](#!)
  * [Recipes: Index](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/recipe-index.html)
  * [Configuring Your Store](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/configuring-your-store.html)
  * [Usage With TypeScript](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/usage-with-typescript.html)
  * [Migrating to Redux](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/migrating-to-redux.html)
  * [Using Object Spread Operator](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/using-object-spread-operator.html)
  * [Reducing Boilerplate](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/reducing-boilerplate.html)
  * [Server Rendering](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/server-rendering.html)
  * [Writing Tests](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/writing-tests.html)
  * [Computing Derived Data](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/computing-derived-data.html)
  * [Implementing Undo History](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/implementing-undo-history.html)
  * [Isolating Redux Sub-Apps](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/isolating-redux-sub-apps.html)
  * [Code Splitting](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/code-splitting.html)
  * [Troubleshooting](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/troubleshooting.html)
  * [Structuring Reducers](#!)
    * [Structuring Reducers](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/structuring-reducers.html)
    * [Prerequisite Concepts](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/prerequisite-concepts.html)
    * [Basic Reducer Structure](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/basic-reducer-structure.html)
    * [Splitting Reducer Logic](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/splitting-reducer-logic.html)
    * [Refactoring Reducers Example](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/refactoring-reducer-example.html)
    * [Using combineReducers](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/using-combinereducers.html)
    * [Beyond combineReducers](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/beyond-combinereducers.html)
    * [Normalizing State Shape](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/normalizing-state-shape.html)
    * [Updating Normalized Data](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/updating-normalized-data.html)
    * [Reusing Reducer Logic](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/reusing-reducer-logic.html)
    * [Immutable Update Patterns](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/immutable-update-patterns.html)
    * [Initializing State](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/initializing-state.html)
* [Understanding Redux](#!)
  * [Thinking in Redux](#!)
    * [Motivation](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/understanding/thinking-in-redux/motivation.html)
    * [Three Principles](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/understanding/thinking-in-redux/three-principles.html)
    * [Glossary](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/understanding/thinking-in-redux/glossary.html)
  * [History and Design](#!)
    * [Prior Art](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/understanding/history-and-design/prior-art.html)
    * [Middleware](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/understanding/history-and-design/middleware.html)
* [FAQ](#!)
  * [FAQ Index](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/faq.html)
  * [General](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/md-docs/general.html)
  * [Reducers](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/md-docs/reducers.html)
  * [Organizing State](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/md-docs/organizing-state.html)
  * [Store Setup](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/md-docs/store-setup.html)
  * [Actions](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/md-docs/actions.html)
  * [Immutable Data](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/md-docs/immutable-data.html)
  * [Code Structure](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/md-docs/code-structure.html)
  * [Performance](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/md-docs/performance.html)
  * [Design Decisions](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/md-docs/design-decisions.html)
  * [React Redux](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/md-docs/react-redux.html)
  * [Miscellaneous](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/md-docs/miscellaneous.html)
* [Style Guide](#!)
  * [Style Guide: Best Practices](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/style-guide/style-guide.html)
* [API Reference](#!)
  * [API Reference](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/api/api-reference.html)
  * [createStore](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/api/createstore.html)
  * [Store](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/api/store.html)
  * [combineReducers](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/api/combinereducers.html)
  * [applyMiddleware](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/api/applymiddleware.html)
  * [bindActionCreators](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/api/bindactioncreators.html)
  * [compose](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/api/compose.html)
* [Redux Toolkit](#!)
  * [Redux Toolkit: Overview](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/redux-toolkit/overview.html)

## Redux FAQ: Actions[#](#redux-faq-actions)

### Table of Contents[#](#table-of-contents)

* [Redux FAQ: Actions](#redux-faq-actions)
  * [Table of Contents](#table-of-contents)
  * [Actions](#actions)
    * [Why should `type` be a string, or at least serializable? Why should my action types be constants?](#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
      * [Further information](#further-information)
    * [Is there always a one-to-one mapping between reducers and actions?](#is-there-always-a-one-to-one-mapping-between-reducers-and-actions)
      * [Further information](#further-information-1)
    * [How can I represent “side effects” such as AJAX calls? Why do we need things like “action creators”, “thunks”, and “middleware” to do async behavior?](#how-can-i-represent-side-effects-such-as-ajax-calls-why-do-we-need-things-like-action-creators-thunks-and-middleware-to-do-async-behavior)
      * [Further information](#further-information-2)
    * [What async middleware should I use? How do you decide between thunks, sagas, observables, or something else?](#what-async-middleware-should-i-use-how-do-you-decide-between-thunks-sagas-observables-or-something-else)
    * [Should I dispatch multiple actions in a row from one action creator?](#should-i-dispatch-multiple-actions-in-a-row-from-one-action-creator)
      * [Further information](#further-information-3)

### Actions[#](#actions)

#### Why should `type` be a string, or at least serializable? Why should my action types be constants?[#](#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)

As with state, serializable actions enable several of Redux's defining features, such as time travel debugging, and recording and replaying actions. Using something like a `Symbol` for the `type` value or using `instanceof` checks for actions themselves would break that. Strings are serializable and easily self-descriptive, and so are a better choice. Note that it *is* okay to use Symbols, Promises, or other non-serializable values in an action if the action is intended for use by middleware. Actions only need to be serializable by the time they actually reach the store and are passed to the reducers.

We can't reliably enforce serializable actions for performance reasons, so Redux only checks that every action is a plain object, and that the `type` is defined. The rest is up to you, but you might find that keeping everything serializable helps debug and reproduce issues.

Encapsulating and centralizing commonly used pieces of code is a key concept in programming. While it is certainly possible to manually create action objects everywhere, and write each `type` value by hand, defining reusable constants makes maintaining code easier. If you put constants in a separate file, you can [check your `import` statements against typos](https://github.com/bgoonz/Learning-Redux/blob/master/www.npmjs.com/package/eslint-plugin-import.html) so you can't accidentally use the wrong string.

**Further information**[**#**](#further-information)

**Documentation**

* [Reducing Boilerplate](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/reducing-boilerplate.html#actions)

**Discussion**

* [#384: Recommend that Action constants be named in the past tense](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reduxjs/redux/issues/384.html)
* [#628: Solution for simple action creation with less boilerplate](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reduxjs/redux/issues/628.html)
* [#1024: Proposal: Declarative reducers](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reduxjs/redux/issues/1024.html)
* [#1167: Reducer without switch](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reduxjs/redux/issues/1167.html)
* [Stack Overflow: Why do you need 'Actions' as data in Redux?](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/q/34759047/62937.html)
* [Stack Overflow: What is the point of the constants in Redux?](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/q/34965856/62937.html)

#### Is there always a one-to-one mapping between reducers and actions?[#](#is-there-always-a-one-to-one-mapping-between-reducers-and-actions)

No. We suggest you write independent small reducer functions that are each responsible for updates to a specific slice of state. We call this pattern “reducer composition”. A given action could be handled by all, some, or none of them. This keeps components decoupled from the actual data changes, as one action may affect different parts of the state tree, and there is no need for the component to be aware of this. Some users do choose to bind them more tightly together, such as the “ducks” file structure, but there is definitely no one-to-one mapping by default, and you should break out of such a paradigm any time you feel you want to handle an action in many reducers.

**Further information**[**#**](#further-information-1)

**Documentation**

* [Fundamentals: State, Actions, Reducers](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/fundamentals/part-3-state-actions-reducers.html)
* [Recipes: Structuring Reducers](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/recipes/structuring-reducers/structuring-reducers.html)

**Discussions**

* [Twitter: most common Redux misconception](https://github.com/bgoonz/Learning-Redux/blob/master/twitter.com/dan_abramov/status/682923564006248448.html)
* [#1167: Reducer without switch](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reduxjs/redux/issues/1167.html)
* [Reduxible #8: Reducers and action creators aren't a one-to-one mapping](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/pitzcarraldo/reduxible/issues/8.html)
* [Stack Overflow: Can I dispatch multiple actions without Redux Thunk middleware?](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/questions/35493352/can-i-dispatch-multiple-actions-without-redux-thunk-middleware/35642783.html)

#### How can I represent “side effects” such as AJAX calls? Why do we need things like “action creators”, “thunks”, and “middleware” to do async behavior?[#](#how-can-i-represent-side-effects-such-as-ajax-calls-why-do-we-need-things-like-action-creators-thunks-and-middleware-to-do-async-behavior)

This is a long and complex topic, with a wide variety of opinions on how code should be organized and what approaches should be used.

Any meaningful web app needs to execute complex logic, usually including asynchronous work such as making AJAX requests. That code is no longer purely a function of its inputs, and the interactions with the outside world are known as [“side effects”](https://github.com/bgoonz/Learning-Redux/blob/master/en.wikipedia.org/wiki/Side_effect_\(computer_science\).html)

Redux is inspired by functional programming, and out of the box, has no place for side effects to be executed. In particular, reducer functions *must* always be pure functions of `(state, action) => newState`. However, Redux's middleware makes it possible to intercept dispatched actions and add additional complex behavior around them, including side effects.

In general, Redux suggests that code with side effects should be part of the action creation process. While that logic *can* be performed inside of a UI component, it generally makes sense to extract that logic into a reusable function so that the same logic can be called from multiple places—in other words, an action creator function.

The simplest and most common way to do this is to add the [Redux Thunk](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reduxjs/redux-thunk.html) middleware that lets you write action creators with more complex and asynchronous logic. Another widely-used method is [Redux Saga](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/redux-saga/redux-saga.html) which lets you write more synchronous-looking code using generators, and can act like “background threads” or “daemons” in a Redux app. Yet another approach is [Redux Loop](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/redux-loop/redux-loop.html), which inverts the process by allowing your reducers to declare side effects in response to state changes and have them executed separately. Beyond that, there are *many* other community-developed libraries and ideas, each with their own take on how side effects should be managed.

**Further information**[**#**](#further-information-2)

**Documentation**

* [Redux Fundamentals: Async Logic and Data Flow](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/fundamentals/part-6-async-logic.html)
* [Redux Fundamentals: Store - Middleware](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/fundamentals/part-4-store.html#middleware)

**Articles**

* [Redux Side-Effects and You](https://github.com/bgoonz/Learning-Redux/blob/master/medium.com/javascript-and-opinions/redux-side-effects-and-you-66f2e0842fc3.html)
* [Pure functionality and side effects in Redux](https://github.com/bgoonz/Learning-Redux/blob/master/blog.hivejs.org/building-the-ui-2/index.html)
* [From Flux to Redux: Async Actions the easy way](https://github.com/bgoonz/Learning-Redux/blob/master/danmaz74.me/2015/08/19/from-flux-to-redux-async-actions-the-easy-way/index.html)
* [React/Redux Links: "Redux Side Effects" category](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/markerikson/react-redux-links/blob/master/redux-side-effects.html)
* [Gist: Redux-Thunk examples](https://github.com/bgoonz/Learning-Redux/blob/master/gist.github.com/markerikson/ea4d0a6ce56ee479fe8b356e099f857e.html)

**Discussions**

* [#291: Trying to put API calls in the right place](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reduxjs/redux/issues/291.html)
* [#455: Modeling side effects](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reduxjs/redux/issues/455.html)
* [#533: Simpler introduction to async action creators](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reduxjs/redux/issues/533.html)
* [#569: Proposal: API for explicit side effects](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reactjs/redux/pull/569.html)
* [#1139: An alternative side effect model based on generators and sagas](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reactjs/redux/issues/1139.html)
* [Stack Overflow: Why do we need middleware for async flow in Redux?](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/questions/34570758/why-do-we-need-middleware-for-async-flow-in-redux.html)
* [Stack Overflow: How to dispatch a Redux action with a timeout?](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/questions/35411423/how-to-dispatch-a-redux-action-with-a-timeout/35415559.html)
* [Stack Overflow: Where should I put synchronous side effects linked to actions in redux?](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/questions/32982237/where-should-i-put-synchronous-side-effects-linked-to-actions-in-redux/33036344.html)
* [Stack Overflow: How to handle complex side-effects in Redux?](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/questions/32925837/how-to-handle-complex-side-effects-in-redux/33036594.html)
* [Stack Overflow: How to unit test async Redux actions to mock ajax response](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/questions/33011729/how-to-unit-test-async-redux-actions-to-mock-ajax-response/33053465.html)
* [Stack Overflow: How to fire AJAX calls in response to the state changes with Redux?](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/questions/35262692/how-to-fire-ajax-calls-in-response-to-the-state-changes-with-redux/35675447.html)
* [Reddit: Help performing Async API calls with Redux-Promise Middleware.](https://github.com/bgoonz/Learning-Redux/blob/master/www.reddit.com/r/reactjs/comments/469iyc/help_performing_async_api_calls_with_reduxpromise/index.html)
* [Twitter: possible comparison between sagas, loops, and other approaches](https://github.com/bgoonz/Learning-Redux/blob/master/twitter.com/dan_abramov/status/689639582120415232.html)

#### What async middleware should I use? How do you decide between thunks, sagas, observables, or something else?[#](#what-async-middleware-should-i-use-how-do-you-decide-between-thunks-sagas-observables-or-something-else)

There are [many async/side effect middlewares available](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/markerikson/redux-ecosystem-links/blob/master/side-effects.html), but the most commonly used ones are [`redux-thunk`](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reduxjs/redux-thunk.html), [`redux-saga`](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/redux-saga/redux-saga.html), and [`redux-observable`](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/redux-observable/redux-observable.html). These are different tools, with different strengths, weaknesses, and use cases.

As a general rule of thumb:

* Thunks are best for complex synchronous logic (especially code that needs access to the entire Redux store state), and simple async logic (like basic AJAX calls). With the use of `async/await`, it can be reasonable to use thunks for some more complex promise-based logic as well.
* Sagas are best for complex async logic and decoupled "background thread"-type behavior, especially if you need to listen to dispatched actions (which is something that can't be done with thunks). They require familiarity with ES6 generator functions and `redux-saga`'s "effects" operators.
* Observables solve the same problems as sagas, but rely on RxJS to implement async behavior. They require familiarity with the RxJS API.

We recommend that most Redux users should start with thunks, and then add an additional side effect library like sagas or observables later if their app really requires handling for more complex async logic.

Since sagas and observables have the same use case, an application would normally use one or the other, but not both. However, note that **it's absolutely fine to use both thunks and either sagas or observables together**, because they solve different problems.

**Articles**

* [Decembersoft: What is the right way to do asynchronous operations in Redux?](https://github.com/bgoonz/Learning-Redux/blob/master/decembersoft.com/posts/what-is-the-right-way-to-do-asynchronous-operations-in-redux/index.html)
* [Decembersoft: Redux-Thunk vs Redux-Saga](https://github.com/bgoonz/Learning-Redux/blob/master/decembersoft.com/posts/redux-thunk-vs-redux-saga/index.html)
* [Redux-Thunk vs Redux-Saga: an overview](https://github.com/bgoonz/Learning-Redux/blob/master/medium.com/@shoshanarosenfield/redux-thunk-vs-redux-saga-93fe82878b2d.html)
* [Redux-Saga V.S. Redux-Observable](https://github.com/bgoonz/Learning-Redux/blob/master/hackmd.io/@2qVnJRlJRHCk20dvVxsySA/H1xLHUQ8e8ce5.html#side-by-side-comparison)

**Discussions**

* [Reddit: discussion of using thunks and sagas together, and pros and cons of sagas](https://github.com/bgoonz/Learning-Redux/blob/master/www.reddit.com/r/reactjs/comments/8vglo0/react_developer_map_by_adamgolab/e1nr597/index.html)
* [Stack Overflow: Pros/cons of using redux-saga with ES6 generators vs redux-thunk with ES2017 async/await](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/questions/34930735/pros-cons-of-using-redux-saga-with-es6-generators-vs-redux-thunk-with-es2017-asy.html)
* [Stack Overflow: Why use Redux-Observable over Redux-Saga?](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/questions/40021344/why-use-redux-observable-over-redux-saga/40027778.html#40027778)

#### Should I dispatch multiple actions in a row from one action creator?[#](#should-i-dispatch-multiple-actions-in-a-row-from-one-action-creator)

There's no specific rule for how you should structure your actions. Using an async middleware like Redux Thunk certainly enables scenarios such as dispatching multiple distinct but related actions in a row, dispatching actions to represent progression of an AJAX request, dispatching actions conditionally based on state, or even dispatching an action and checking the updated state immediately afterwards.

In general, ask if these actions are related but independent, or should actually be represented as one action. Do what makes sense for your own situation but try to balance the readability of reducers with readability of the action log. For example, an action that includes the whole new state tree would make your reducer a one-liner, but the downside is now you have no history of *why* the changes are happening, so debugging gets really difficult. On the other hand, if you emit actions in a loop to keep them granular, it's a sign that you might want to introduce a new action type that is handled in a different way.

Try to avoid dispatching several times synchronously in a row in the places where you're concerned about performance. There are a number of addons and approaches that can batch up dispatches as well.

**Further information**[**#**](#further-information-3)

**Documentation**

* [FAQ: Performance - Reducing Update Events](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/md-docs/performance.html#performance-update-events)

**Articles**

* [Idiomatic Redux: Thoughts on Thunks, Sagas, Abstraction, and Reusability](https://github.com/bgoonz/Learning-Redux/blob/master/blog.isquaredsoftware.com/2017/01/idiomatic-redux-thoughts-on-thunks-sagas-abstraction-and-reusability/index.html#multiple-dispatching)

**Discussions**

* [#597: Valid to dispatch multiple actions from an event handler?](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reactjs/redux/issues/597.html)
* [#959: Multiple actions one dispatch?](https://github.com/bgoonz/Learning-Redux/blob/master/github.com/reactjs/redux/issues/959.html)
* [Stack Overflow: Should I use one or several action types to represent this async action?](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/questions/33637740/should-i-use-one-or-several-action-types-to-represent-this-async-action/33816695.html)
* [Stack Overflow: Do events and actions have a 1:1 relationship in Redux?](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/questions/35406707/do-events-and-actions-have-a-11-relationship-in-redux/35410524.html)
* [Stack Overflow: Should actions be handled by reducers to related actions or generated by action creators themselves?](https://github.com/bgoonz/Learning-Redux/blob/master/stackoverflow.com/questions/33220776/should-actions-like-showing-hiding-loading-screens-be-handled-by-reducers-to-rel/33226443.html#33226443)
* [Twitter: "Good thread on the problems with Redux Thunk..."](https://github.com/bgoonz/Learning-Redux/blob/master/twitter.com/dan_abramov/status/800310164792414208.html)

Previous

« Store Setup

Next

Immutable Data »

* [Table of Contents](#table-of-contents)
* [Actions](#actions)
  * [Why should `type` be a string, or at least serializable? Why should my action types be constants?](#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
  * [Is there always a one-to-one mapping between reducers and actions?](#is-there-always-a-one-to-one-mapping-between-reducers-and-actions)
  * [How can I represent “side effects” such as AJAX calls? Why do we need things like “action creators”, “thunks”, and “middleware” to do async behavior?](#how-can-i-represent-side-effects-such-as-ajax-calls-why-do-we-need-things-like-action-creators-thunks-and-middleware-to-do-async-behavior)
  * [What async middleware should I use? How do you decide between thunks, sagas, observables, or something else?](#what-async-middleware-should-i-use-how-do-you-decide-between-thunks-sagas-observables-or-something-else)
  * [Should I dispatch multiple actions in a row from one action creator?](#should-i-dispatch-multiple-actions-in-a-row-from-one-action-creator)

**Docs**

* [Getting Started](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/introduction/getting-started.html)
* [Tutorial](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/tutorials/essentials/part-1-overview-concepts.html)
* [FAQ](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/faq.html)
* [API Reference](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/api/api-reference.html)

**Community**

* [Reactiflux Discord](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/official/discord.com/invite/0ZcbPKXt5bZ6au5t.html)
* [Stack Overflow](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/official/stackoverflow.com/questions/tagged/redux.html)
* [Feedback](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/introduction/getting-started.html#help-and-discussion)

**More**

* [GitHub](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/official/github.com/reduxjs/redux.html)
* [![Deploys by Netlify](https://github.com/bgoonz/Learning-Redux/blob/master/www.netlify.com/img/global/badges/netlify-color-accent.svg)](https://github.com/bgoonz/Learning-Redux/blob/master/www.netlify.com/index.html)

[![Redux Logo](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/official/d33wubrfki0l68.cloudfront.net/0834d0215db51e91525a25acf97433051f280f2f/c30f5/img/redux.svg)![Redux Logo](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/official/d33wubrfki0l68.cloudfront.net/0834d0215db51e91525a25acf97433051f280f2f/c30f5/img/redux.svg)](https://github.com/bgoonz/Learning-Redux/blob/master/DOCS/index.html)

Copyright © 2015–2021 Dan Abramov and the Redux documentation authors.
