How do you handle events in React?

Beginner

Answer

React uses SyntheticEvents, which are wrappers around native events that provide consistent behavior across browsers:

function Button() {
  const handleClick = (event) => {
    event.preventDefault();
    console.log('Button clicked!');
    console.log('Event type:', event.type);
  };
  
  return (
    <button onClick={handleClick}>
      Click me
    </button>
  );
}