useState Hook
Question
What does useState return?
Hint
useState returns [value, setValue] as an array.
Explanation
useState(initialValue) returns an array of two elements: the current state value and a function to update it. We use array destructuring: const [count, setCount] = useState(0). The setter function triggers a re-render when called. State updates may be asynchronous and batched. The setter can accept a new value or an updater function: setCount(prev => prev + 1) for safe updates based on previous state.
Related Resources
Related Lessons
- State
Learn state.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.