Lesson 18 of 3060%
(Progress persistence is disabled until Phase 9)
React
Beginner
Forms and Inputs
Handling user input in forms.
To read the value of an input field when it changes, we listen to the onChange event.
The event object e contains the new value at e.target.value.
function SearchBox() {
function handleChange(e) {
console.log("User typed:", e.target.value);
}
return <input type="text" onChange={handleChange} />;
}
Try It Yourself