mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-22 21:08:12 +08:00
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
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:
parent
7217d60f5c
commit
b83c747ccd
@ -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.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user