Event Handling in React: onClick, onChange, and More
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.
Build modern UIs with React
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.
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.
Debounce waits until rapid events pause before running code, while throttle runs code at most once per interval. Learn both patterns in React.
Keyboard navigation in React uses Tab to move between components and arrow keys to move inside them. Learn the roving tabindex pattern.
Combine useReducer with context to share reducer state and dispatch down the tree without prop drilling, using a provider and small custom hooks.
Lazy load routes in React with lazy and Suspense. Split route components into smaller bundles and show a fallback while they load.