REACT: State
Learn State in REACT with practical examples.
REACT — State
Overview
State stores UI data that can change over time.
What you'll learn
- useState
- updating state
- re-render
Syntax
const [count,setCount] = useState(0);
Example
import { useState } from "react";
export default function Counter(){
const [count, setCount] = useState(0);
return (
<button onClick={()=>setCount(count+1)}>
Clicks: {count}
</button>
);
}
Notes
- Never mutate state directly.
- State update triggers re-render.