Keep only the minimal state
Classify a value as state only when it changes, is not passed by props, and cannot be derived.
The move: store causes, calculate consequences. State is for information the component must remember between renders. It is not for values that are already known from props, constants, or calculations. In a searchable list, the search text is state because the user changes it. The original list may be props. The filtered list is derived because it can be computed from the list and search text. This distinction is the heart of predictable React. If you store both the cause and the consequence, you must update both perfectly forever. If you store only the cause, React can recalculate the consequence…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in