React State (useState)
State is data that can change over time. The useState hook gives you a value and a function to update it. When you update state, React re-renders the component.
const { useState } = React
function Counter() {
const [count, setCount] = useState(0)
return <button onClick={() => setCount(count + 1)}>Clicked {count} times</button>
}
Try it yourself
Loading editor…
Press Run, then click the button in the result — the count updates without reloading. That is React keeping the screen in sync with the state.