Complete the code to declare a state variable named count with initial value 0.
const [count, setCount] = [1](0);
The useState hook is used to declare state variables in React functional components.
Complete the code to declare a second state variable named name with initial value an empty string.
const [name, setName] = [1]('');
To create a state variable for the name, useState is used with an empty string as the initial value.
Fix the error in the code to update the count state variable by adding 1.
setCount([1] + 1);
To update the count, you use the current value count plus 1. Calling count() is incorrect because count is a variable, not a function.
Fill both blanks to declare two state variables: age starting at 25 and city starting as 'NYC'.
const [age, setAge] = [1](25); const [city, setCity] = [2]('NYC');
Both age and city are state variables, so useState is used for both.
Fill all three blanks to create a component with two state variables and a button that updates count by 1 when clicked.
import React, { [1], [2] } from 'react'; function Counter() { const [count, setCount] = [3](0); return ( <button onClick={() => setCount(count + 1)} aria-label="Increment count"> Count: {count} </button> ); }
The component imports useState and useEffect hooks. The count state is created with useState. The button updates count by 1 on click.