Recall & Review
beginner
What does
event.preventDefault() do in React event handling?It stops the browser's default action for that event, like following a link or submitting a form, allowing you to control what happens next.
Click to reveal answer
beginner
Why might you want to use
event.preventDefault() in a form submit handler?To stop the page from reloading and handle the form data with JavaScript instead, giving a smoother user experience.
Click to reveal answer
beginner
How do you access the event object in a React function component's event handler?
React passes the event object as the first argument to the event handler function.
Click to reveal answer
intermediate
True or False: Calling
event.preventDefault() will stop the event from bubbling up to parent elements.False.
preventDefault() stops the default browser action but does not stop event bubbling. To stop bubbling, use event.stopPropagation().Click to reveal answer
beginner
In React, when handling a link (
<a>) click, what happens if you don't call event.preventDefault()?The browser will follow the link and navigate to the URL, causing a page reload or navigation away from your React app.
Click to reveal answer
What is the main purpose of
event.preventDefault() in React?✗ Incorrect
event.preventDefault() stops the browser's default behavior, like following a link or submitting a form, but does not stop event bubbling.
Which event object method stops the event from bubbling up to parent elements?
✗ Incorrect
event.stopPropagation() stops the event from bubbling up. preventDefault() only stops default browser actions.
In a React form submit handler, what happens if you don't call
event.preventDefault()?✗ Incorrect
Without preventDefault(), the browser submits the form and reloads the page.
How do you get access to the event object in a React event handler?
✗ Incorrect
React passes the event object as the first argument to your event handler function.
Which of these is a common use case for
event.preventDefault() in React?✗ Incorrect
Calling preventDefault() on a link click stops the browser from navigating away.
Explain how and why you would use
event.preventDefault() in a React form submission.Think about what happens when a form submits normally in a browser.
You got /4 concepts.
Describe the difference between
event.preventDefault() and event.stopPropagation() in React event handling.One controls browser behavior, the other controls event flow.
You got /4 concepts.