Lesson 4 of 10
State (useState)
State is data that changes over time and causes the component to re-render. Use the useState hook to create state. It returns the current value and a function to update it.
When state changes, React automatically updates the UI to match.
REACT
import { useState } from "react";
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}