Selectors and Derived State
Learn how to compute derived values from state efficiently, whether in Redux, Zustand, or plain component state.
Derived state is data computed from other state rather than stored independently — for example, a filtered list, a total price, or a boolean like isEmpty computed from an array's length. A selector is simply a function that takes the state (or part of it) and returns a derived value, keeping the 'source of truth' minimal and avoiding state that can drift out of sync with what it's derived from.
A selector is like a calculator that always recomputes totals fresh from the receipt (source state) rather than trusting a sticky note someone wrote down earlier that might not reflect a later returned item — and a memoized selector is a smart calculator that skips redoing the math if the receipt hasn't actually changed.