InterviewHubPRO
Section Overview
Q106

Question 106 of 445

Part 5: React Redux State Management (101 - 134)

24%
React & Modern Frontend (445 Qs)•Part 5: React Redux State Management (101 - 134)

Can I dispatch an action in reducer?

Dispatching an action within a reducer is an anti-pattern. Your reducer should be without side effects, simply digesting the action payload and returning a new state object. Adding listeners and dispatching actions within the reducer can lead to chained actions and other side effects.

Practical Code Example

javascript
// Can you dispatch an action in a reducer?
// NO! Reducers MUST be pure functions without side-effects.
// Dispatching inside a reducer causes infinite loops and throws an error in Redux.