React wraps browser events in synthetic events for consistent cross-browser behavior. You attach handlers via camelCase props like onClick and onChange. This lesson covers patterns for interactive UIs.
Synthetic Events
React's SyntheticEvent wraps the native event. Handlers receive this wrapper, which behaves like the native event for common cases (preventDefault, stopPropagation, target).
In React 17+, events delegate to the root React container, not document, which improves compatibility with multiple React versions on one page.
Alternative: data attributes on the element and read from e.currentTarget.dataset.
Events and Accessibility
Click handlers on non-interactive elements (div, span) hurt accessibility. Use <button> for actions and <a href> for navigation. If you must use a div, add role, tabIndex, and keyboard handlers.
Common Mistakes
Calling the handler during render: onClick={handleClick()}.
Forgetting preventDefault on forms in SPAs.
Using only onClick on divs without keyboard support.
Creating new inline functions on every render in performance-critical lists without need.
Key Takeaways
React uses camelCase synthetic event props.
Pass function references to event props.
Use preventDefault and stopPropagation when needed.
Prefer semantic interactive elements for accessibility.
Pro Tip
Extract repeated inline handlers to named functions when the same list re-renders hundreds of items and profiling shows a cost.
You can handle user events in React. Next, build forms that collect user input.