Dualo
React Basics

State & useState

Give components memory so they can react to user interactions.

1 min read

`useState(initial)` returns a tuple `[value, setValue]`. The setter schedules an update; React batches updates inside event handlers and commits them together.

State is preserved between renders as long as the component stays mounted at the same position in the tree. React identifies state by component identity + position, not by variable name.

Updater form `setValue(prev => next)` avoids stale-closure bugs when multiple updates rely on the previous value within the same event loop.

Diagram

Grounded on https://react.dev/learn/state-a-components-memory