Complete the code to create a state variable called count with initial value 0.
const [count, setCount] = [1](0);
The useState hook creates a state variable and a function to update it.
Complete the code to update the count state by adding 1 when the button is clicked.
<button onClick={() => setCount([1])}>Add 1</button>To increase the count by 1, use count + 1 inside the setter function.
Fix the error in the code to correctly initialize state with an object having a name property.
const [user, setUser] = useState([1]);State should be initialized with an object literal: {name: 'Alice'}.
Fill both blanks to create a state variable called message with initial value 'Hello' and update it to 'Hi'.
const [message, [1]] = useState([2]); setMessage('Hi');
The setter function is usually named starting with 'set'. Initial state is the first value.
Fill all three blanks to create a counter component with state count starting at 0, a button to increment, and display the count.
import React, { [1] } from 'react'; function Counter() { const [count, [2]] = [3](0); return ( <div> <p>Count: {count}</p> <button onClick={() => setCount(count + 1)}>Increment</button> </div> ); }
Import useState, use setCount as setter, and call useState(0) to initialize.