Find: Missing preventDefault
Find the Mistake Easy
Question
What is wrong with this form handler?
Code
function MyForm() {
const handleSubmit = (e) => {
console.log("Submitted!");
};
return (
<form onSubmit={handleSubmit}>
<button type="submit">Submit</button>
</form>
);
}
Hint
What happens by default when a form is submitted?
Explanation
The handler doesn't call e.preventDefault(), so the form submission causes a full page reload. The fix is to add e.preventDefault(); at the top of the handler to prevent the default behavior.
Related Resources
Related Lessons
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.