Handling Events
Part of the React course
A component that only ever renders based on props and state is not interactive on its own, something has to notice when the user clicks a button, types into a field, or presses a key, and turn that into a state update. You already wired one onClick in the previous lesson without stopping to explain it.
React lets you attach event handlers directly to JSX elements using props named after the DOM event they respond to, written in camelCase: onClick for clicks, onChange for input changes, and so on. The value of that prop is a function, one you either define separately or write inline.
Want to learn React Handling Events in a real environment?
Click below, get a fresh Linux box with React ready to go, and work through Handling Events hands-on with an AI tutor that knows your code.
Start this lessonHandling EventsWhat you'll learn
- OnClick handler
- OnChange basics
- Passing functions vs calling them
- Event object
- Passing handlers as props
Read this lesson in your language
All lessons in this course
17 lessons- 1What is React?25 min
- 2JSX and Components30 min
- 3Props30 min
- 4State with useState35 min
- 5Handling Events30 min
- 6Conditional Rendering and Lists30 min
- 7Forms and Controlled Inputs35 min
- 8Effects with useEffect40 min
- 9Data Fetching40 min
- 10Component Composition35 min
- 11Context and useContext35 min
- 12useReducer35 min
- 13Custom Hooks35 min
- 14Performance and Memoization35 min
- 15Routing with React Router40 min
- 16Testing React Components40 min
- 17Capstone: Todo App60 min
