Deriving Values from State
As you can probably tell by now, state is a key concept in React. State allows you to manage data that, when changed, forces React to re-evaluate a component and, ultimately, the UI.
As a developer, you can use state values anywhere in your component (and in your child components, by passing state to them via props). You could, for example, repeat what a user entered like this:
function Repeater() {
const [userInput, setUserInput] = useState('');
function handleChange(event) {
setUserInput(event.target.value);
};
return (
<>
<input type="text" onChange={handleChange} />
<p>You entered: {userInput}</p>
</>
);
};
This component might not be too useful, but it will work, and it does use state.
Often, in order to do more useful things, you will need to use a state value as a basis to derive a new (often more complex) value. For example, instead of simply repeating...