How to Preserve and Reset State with Component Keys
Preserve or reset React state with a component key. A changing key remounts the component and starts its state over.
Build modern UIs with React
Preserve or reset React state with a component key. A changing key remounts the component and starts its state over.
Derived state is any value you can compute during render. Do not store it, or two sources of truth will drift apart.
Type useState in React with TypeScript by letting inference work, or pass a type argument for unions, objects, and arrays.
Event handling is how a React component responds to user input. Attach onClick and onChange handlers, pass functions without calling them, and read the event object.
Pass arguments to a React event handler by wrapping the call in an arrow function. The arrow runs on the event, so data arrives at the right time.
React onChange fires on every edit and keeps controlled fields in sync. Learn the right prop and event property for inputs, selects, and checkboxes.
Read uncontrolled form values in React by letting the DOM hold them and collecting them with new FormData on submit. No per-field state required.
Stop a form from reloading the page in React by calling e.preventDefault() in the submit handler. Then read the values and handle them yourself.
Event bubbling runs handlers from the target up to its parents, while capturing runs top-down. Learn how both directions work in React.
Stop a React event from bubbling to parent handlers by calling e.stopPropagation() inside the handler. Learn when to use it and what it does not do.
A React synthetic event is the event object React passes to your handlers. It wraps the native event and normalizes browser differences.
Handle keyboard events in React with onKeyDown and onKeyUp. Read e.key for the key's meaning and e.code for its physical position.