DEV Community

JT Cho
JT Cho

Posted on

Redux reducers: not to do

Reducers must be:

  1. pure: pure reducer does not mutate the state directly.
  2. side-effect free: reducer does not change a non-local state, nor use an external code. ex) console.log()
  3. synchronous: reducer does not "await" for asynchronous results. ex) HTTP request

If side-effects & async tasks are necessary,

  1. Use them inside components: via useEffect.
  2. Use action creators.

Top comments (0)