The initial state value. Can be any type: number, string, boolean, object, or array.
Returns
A two-element array:
[0] — The current state value.
[1] — A setter function that updates the state and triggers a re-render.
Usage
Counter
Toggle visibility
Object state
Notes
- Each component instance maintains its own independent state. Two instances of the same component do not share
useState values.
- The
initialValue is only used on the first render. Subsequent re-renders return the current state.
- Calling the setter with the same value may still trigger a re-render.
- For state shared across multiple components, use useStore instead.
useState must be called inside a component body function, not at the top level.
See Also