JavaScript & React Events
A website without events is just a poster. Events bring your application to life, allowing it to react to user inputs such as clicks, keyboard presses, and form submissions.
Mouse Events
Mouse events fire when the user interacts with the pointing device. The most famous one is click. In vanilla JavaScript, you use addEventListener('click', ...). In React, we use the camelCase version: onClick directly on the JSX element.
Other useful mouse events include mouseenter (when the mouse hovers over an element) and mouseleave.
Keyboard Events
Keyboard events track keystrokes. You commonly attach these to the global document or specific input fields. The events are keydown (key pressed) and keyup (key released).
The Event Object (e) passed to the callback function contains vital information, specifically e.key, which tells you exactly which character or action key (like 'Enter' or 'Escape') was pressed.
Form Events
Forms are the backbone of user data input. The submit event triggers when a form is sent. However, natively, browsers refresh the page to send the data to a server.
In modern web development (like React apps), we want to handle data via JavaScript (e.g., using fetch API) without refreshing. To stop the browser from its default behavior, you must call e.preventDefault() inside your submit handler.
