Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Rules for Reducers | Redux in Practice
Introduction to Redux
course content

Kursinnehåll

Introduction to Redux

Introduction to Redux

1. Getting Started
2. Fundamental Concepts
3. Redux in Practice
4. Creating a React-Redux Application

book
Rules for Reducers

There are certain rules while using Redux Reducers which we need to follow to avoid certain bugs or surprises.

  • Reducers should use only the state and action arguments to calculate the new state. They shouldn't access any external values;

  • Reducers must not perform asynchronous logic or side effects such as making API calls or running timers etc.;

  • The state should not be directly modified inside the reducer functions, instead, the reducer function should return a duplicate state object with updated values. This rule only applies when creating reducers manually. If we use createSlice to create a slice, we can modify the state directly.

It is important to note that in the case of createSlice reducers, we directly modify the state object, however, in the backend, Redux creates a new duplicate object and assigns it the new changes, so the rule is being followed, but in the backend.

question mark

In which case can we directly modify the state?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 10

Fråga AI

expand
ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

course content

Kursinnehåll

Introduction to Redux

Introduction to Redux

1. Getting Started
2. Fundamental Concepts
3. Redux in Practice
4. Creating a React-Redux Application

book
Rules for Reducers

There are certain rules while using Redux Reducers which we need to follow to avoid certain bugs or surprises.

  • Reducers should use only the state and action arguments to calculate the new state. They shouldn't access any external values;

  • Reducers must not perform asynchronous logic or side effects such as making API calls or running timers etc.;

  • The state should not be directly modified inside the reducer functions, instead, the reducer function should return a duplicate state object with updated values. This rule only applies when creating reducers manually. If we use createSlice to create a slice, we can modify the state directly.

It is important to note that in the case of createSlice reducers, we directly modify the state object, however, in the backend, Redux creates a new duplicate object and assigns it the new changes, so the rule is being followed, but in the backend.

question mark

In which case can we directly modify the state?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 10
Vi beklagar att något gick fel. Vad hände?
some-alt