← React Beginner Questions - Set 7 Q66

What is a state in React?

React Beginner Questions - Set 7

Example

function Toggle() {
  const [on, setOn] = useState(false);   // remembered across renders
  return <button onClick={() => setOn(o => !o)}>{on ? 'ON' : 'OFF'}</button>;
}

What to notice

← Back to the question list