FrontendDeveloper.in

React question detail

What are the guidelines to be followed for writing reducers?

There are two guidelines to be taken care while writing reducers in your code.

  1. Reducers must be pure without mutating the state. That means, same input always returns the same output. These reducers run during rendering time similar to state updater functions. So these functions should not send any requests, schedule time outs and any other side effects.

  2. Each action should describe a single user interaction even though there are multiple changes applied to data. For example, if you "reset" registration form which has many user input fields managed by a reducer, it is suggested to send one "reset" action instead of creating separate action for each fields. The proper ordering of actions should reflect the user interactions in the browser and it helps a lot for debugging purpose.

Back to all React questions
Get LinkedIn Premium at Rs 399