Menu

Event Handling & Controlled Components

Event Handling & Controlled Components

A. Event handling is how the app responds to user actions — clicks, typing, hovering. onClick triggers product selection, star rating, and review submission; onChange updates the review text; onMouseEnter/onMouseLeave power the star hover effect.

Inside the modal, clicking outside closes it, but clicking inside prevents that using event propagation (e.stopPropagation()), so the modal doesn't accidentally close on its own content. After a review is submitted, a setTimeout is used inside the click handler to briefly show a success message before automatically closing the modal.

BControlled components are form elements whose value is fully managed by React state rather than the browser. The review textarea is a controlled component, since its value comes directly from the text state and updates only through onChange, and the star rating input works the same way, staying in sync with the rating state at all times.