State Management · Senior · Question 67 of 75

When does useSelector(selector, shallowEqual) help?

const { name, email } = useSelector((s) => ({ name: s.user.name, email: s.user.email }), shallowEqual);

Explanation

Without it, the new object fails === and re-renders on every action. Alternatives: select primitives separately or use a memoized selector.

Further reading

Problem with a question

State Management · Senior · question 67

Test yourself

Take the State Management · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz