preventDefault
A method on an event that cancels the browser's built-in action, such as submitting a form or following a link.
In more detail
Composed handlers check event.defaultPrevented so a consumer can opt out of a component's internal behaviour. It does not stop the event from bubbling to parents.
Examples
In the browser: It only works on cancelable events, and the defaultPrevented property shows whether it was called. Inside a passive listener the call is ignored, which is what lets the browser scroll without waiting.When a React 19 form action prop is a function, React intercepts the submission itself, so the manual call is no longer needed.Related terms
- event handler — A function that runs when something happens to an element, such as a click (onClick) or a key press (onKeyDown).
- event bubbling — The way an event on an element also triggers handlers on its parent elements, one level at a time up the tree.
- stopPropagation — An event method that stops the event from travelling to further elements, while other listeners on the current element still run.
- passive event listener — An event listener registered with { passive: true }, which promises never to call preventDefault, so the browser can scroll immediately without waiting for it.
- cancelable option — An event option saying listeners may call preventDefault to cancel the action the event announces.
- useActionState — The React hook that wraps an Action and returns its latest result, a function to trigger it, and an isPending flag.
- FormData — A browser object holding the name and value of every field in a submitted form.
Taught in
- Polymorphism & Slotted Composition: The asChild Pattern — Design Systems & Component Engineering
- Event Phases: Capturing, Target And Bubbling Demystified — Frontend Architecture & Web Platform
- Passive Listeners, Scroll Performance And Touch Interactions — Frontend Architecture & Web Platform
- CustomEvent Dispatching And Decoupled Component Event Buses — Frontend Architecture & Web Platform
- useActionState: Async Action Handlers And Pending States — React 19 & Modern Component Architecture