Introduction to useState
State is how React components "remember" information between renders. The useState hook is the primary way to add state to function components.
What is State?
State is data that can change over time and causes the component to re-render when it changes:
Loading React playground...
How useState Works
Loading React playground...
useState Syntax
The hook returns an array with exactly two elements:
Loading React playground...
Different Initial Values
State can hold any JavaScript value:
Loading React playground...
Exercise: State Declaration
Loading exercise...
Exercise: State Updates
Loading exercise...
Exercise: Complex State Update
Loading exercise...
Key Takeaways
- State persists between renders - Unlike regular variables
- useState returns an array -
[value, setValue] - Naming convention -
[thing, setThing] - Any value type - Numbers, strings, booleans, arrays, objects
- Never mutate state - Always return new values

