React & Modern Frontend (445 Qs)•Part 10: Modern React 18, React 19 & Next.js Patterns (317 - 353)
How do you debug a Redux performance problem?
A practical, step-by-step approach:
- Confirm it's actually Redux: use the React DevTools Profiler to see which components re-render and how often, before assuming Redux is the culprit.
- Inspect actions/state with Redux DevTools: check how frequently actions are dispatched and how large/deeply nested the state diffs are on each action.
- Look for unstable selector results: a selector that returns a new object/array/function on every call (e.g.,
state => state.items.filter(...)) breaksuseSelector's reference equality check and forces re-renders even when nothing meaningful changed. Wrap it increateSelector(Q335). - Check for over-broad
useSelectorcalls: selecting an entire slice (state.user) instead of the specific field needed (state.user.name) causes re-renders on unrelated field changes (Q334). - Verify normalization: deeply nested/duplicated state (Q336) often causes broad reference changes on every update; normalizing narrows down what actually changes.
- Check for missing memoization on connected children: wrap presentational components in
React.memoso a parent re-render doesn't cascade if their own props are unchanged. - Use the
why-did-you-renderlibrary (or React DevTools' "highlight updates") to visually confirm exactly which components re-render and why. - Measure, don't guess: use the Profiler's flame chart/ranked view to confirm the fix actually reduced render counts/time before moving on.
Practical Code Example
text
// Debugging Redux Performance:
// 1. Redux DevTools: Profile action dispatch frequency
// 2. React DevTools Profiler: Check which components re-render on state changes
// 3. Reselect: Verify selectors aren't returning new object references on every call