fix(curriculum): Explain Controlled Inputs in Fruit Search App (#61266)
Some checks failed
i18n - Build Validation / Validate i18n Builds (22) (push) Has been cancelled
CI - Node.js / Lint (22) (push) Has been cancelled
CI - Node.js / Build (22) (push) Has been cancelled
CI - Node.js / Test (22) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (22) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 22) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 22) (push) Has been cancelled
i18n - Download Client UI / Client (push) Has been cancelled

Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com>
Co-authored-by: Sem Bauke <semboot699@gmail.com>
This commit is contained in:
Giftea ☕ 2025-08-08 23:38:14 +01:00 committed by GitHub
parent 7217d60f5c
commit b83c747ccd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,7 +7,22 @@ dashedName: step-5
# --description--
In previous lectures, you learned about controlled inputs, where form elements are tied directly to state variables in React.
In React, <dfn>controlled inputs</dfn> are a standard way to handle form data, where the input's value is synced with the component's state.
```jsx
const MyForm = () => {
const [name, setName] = useState("");
return (
<>
<label htmlFor="name">Your name</label>
<input type="text" value={name} id="name" />
</>
);
}
```
You will learn more about this pattern in a future lesson.
To track what the user types into the search input field, create a state variable named `query` with an initial value of an empty string (`''`). Also define its corresponding setter function, `setQuery`, using the `useState` Hook.