State Management · Middle · Question 14 of 75

Why does this selector re-render the component on every dispatched action?

const done = useSelector((s) => s.todos.filter((t) => t.done));

Explanation

useSelector reruns after every dispatch and compares results with ===. Use a memoized selector from createSelector, which returns the same array as long as s.todos hasn't changed.

Further reading

Problem with a question

State Management · Middle · question 14

Test yourself

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

Take this quiz