e.preventDefault() stops the browser's default action for an event, most famously the full page reload caused by submitting a form. React forms almost always call it first inside onSubmit and then handle the data through controlled state, which gives you a submission without a page refresh. It is a one-line call, but forgetting it is one of the most common React form bugs.
Group
Rendering & State
Kind
API
Since
Earliest React versions
ℹ️ Info The editor transpiles JSX to JavaScript and renders the real UI in a sandbox; components mount automatically — no manual render call needed.
📝 Syntax
function handleSubmit(e) {
e.preventDefault() // Stops the browser's default action (such as reloading the page)
// Handle the submission with state here
}
<form onSubmit={handleSubmit}>
⚙️ Parameters
e (event object)
The React synthetic event; preventDefault can only be called while the handler runs synchronously, so it cannot be stored and called later.
Returns:No return value (undefined); after the call the browser's default action for that event no longer happens.
▶ Example
The example runs out of the box: it auto-renders when expanded, and edits take effect instantly.
Output:
A search form: type a keyword and click "Search" and the page does not reload, while "Searched: xxx" appears below; submitting an empty value asks for a keyword instead — the default full page reload is successfully prevented.
⚠️ Warning Preventing the page reload relies on e.preventDefault(); returning false does nothing at all in React.
💡 Tip If a plain button inside a form should not submit it, giving it type="button" also avoids the default behavior.
ℹ️ Info preventDefault stops the default action while stopPropagation stops the event from bubbling; the two are independent and you pick the one you need.
Q Why does submitting a React form reload the page?
A Because the browser has a default action for form submissions. Call e.preventDefault() on the first line of the onSubmit handler to block the reload and process the data with state instead.
Q What does e.preventDefault() do?
A It cancels the browser's default action for the event: the form does not reload, an anchor does not navigate, the context menu does not appear. It only cancels the default action and does not stop the event from propagating.
Q What is the difference between preventDefault and stopPropagation?
A The first blocks the "default action" (such as reloading the page), the second blocks the event from continuing to bubble up to parent elements; they do not affect each other and can be called together.
Web-Tutorial Tech Team
A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.