React · Junior · Question 11 of 75
What does useState(0) return?
- 1An object
{ value, setValue } - ✓Correct answer: An array of the current value and a function to update it
- 3Only the current value; updates go through
this.setState
Explanation
const [count, setCount] = useState(0) - array destructuring lets you name the variables however you like. The initial value is used only on the first render. If computing it is expensive, pass a function: useState(() => compute()).