Complete the code to import the useState hook from React.
import React, { [1] } from 'react';
The useState hook is imported from React to manage state in functional components.
Complete the code to declare a state variable called count with initial value 0.
const [count, [1]] = useState(0);
The second element returned by useState is the setter function to update the state variable.
Fix the error in the code to update the count state by adding 1.
setCount([1] + 1);
To update the state, use the current state variable count plus 1 inside the setter function.
Fill both blanks to create a button that increases count when pressed.
<Button title="Increase" onPress={() => [1]([2] + 1)} />
The onPress handler calls setCount with the current count plus 1 to increase the count.
Fill all three blanks to create a functional component that shows count and a button to increase it.
function Counter() {
const [[1], [2]] = useState(0);
return (
<View>
<Text>{ [1] }</Text>
<Button title="Add" onPress={() => [2]([1] + 1)} />
</View>
);
}The state variable is count, the setter is setCount, and the displayed value is count.