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));- ✓Correct answer:
filterreturns a new array every time, so the reference always changes - 2
useSelectoralways re-renders on any action - 3Selectors can't use array methods
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.