Controlling the DOM Cascade in React
"In React, we are building a declarative UI, but the underlying browser still wants to do things its own way. Mastery of event prevention is the bridge between browser defaults and custom logic."
1. The Default Submission Problem
HTML forms have been refreshing pages since 1993. In a modern SPA (Single Page Application), we want to avoid this at all costs. When you use onSubmit, React passes a SyntheticEvent to your handler. Calling e.preventDefault() tells the browser: "I've got this, don't reload the window."
2. Bubbling and StopPropagation
Imagine a 'Delete' button inside a 'Card' component. If both have click handlers, clicking the button will trigger both. This is often unintended. e.stopPropagation() effectively creates a barrier, ensuring that the event doesn't travel further up the tree.
e.stopPropagation() more predictable when mixing React with non-React code.