State is used to store and manage data that changes over time in a React component. When state changes, React automatically re-renders the component to reflect the updated data.
State is local to a component
It can change based on user interaction or logic
Updating state causes the UI to update
useStateIn functional components, state is managed using the useState hook.
count → current state value
setCount → function to update state
0 → initial state value
This is recommended when the new state depends on the old state.
Update part of the state:
| State | Props |
|---|---|
| Managed inside component | Passed from parent |
| Can change | Read-only |
| Triggers re-render | Does not change itself |
Form inputs
Toggle buttons
Counters
Modal visibility
API data storage
❌ Do not modify state directly
✅ Always use the setter function
State updates may be asynchronous
State holds dynamic data
useState is the most common hook
Updating state re-renders the component
Use previous state when needed
Take quizzes related to this topic and see where you stand!
Start Quiz Now