Skip to content

Instantly share code, notes, and snippets.

@alfonsodev
Forked from kof/action-creator-vs-reducer.md
Created October 22, 2017 11:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfonsodev/34cef8b8a7c74832f9fa149fae98b8b6 to your computer and use it in GitHub Desktop.
Save alfonsodev/34cef8b8a7c74832f9fa149fae98b8b6 to your computer and use it in GitHub Desktop.
Action creator vs. reducer

When should you use action creator and when reducer?

Action creator

  • you need to have side effects
  • you need to read from store to decide what to do
  • you need to dispatch more than one action
  • action produced by action creator needs to contain all the data reducer can need to shape the components state

Reducer

  • should not have any side effects
  • should not read global application state
  • should not manipulate data structures passed with the action, it should only pick the right data and merge it into state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment