Lesson 17 of 3057%

(Progress persistence is disabled until Phase 9)

React
Beginner

Event Handling

Listening to user interactions.

React events are named using camelCase, rather than lowercase. With JSX, you pass a function as the event handler, rather than a string.

function App() {
  const [count, setCount] = React.useState(0);

  function handleClick() {
    setCount(count + 1);
  }

  return (
    <button onClick={handleClick}>
      Clicked {count} times
    </button>
  );
}

Notice we pass handleClick, NOT handleClick(). We want to pass the function itself, not the result of calling it immediately!

Try It Yourself

Lesson Progress

Take QuizBuild a React Project