Q4: How does the useState Hook work?
The useState hook allows functional components to manage local state. It accepts an initial state value as an argument and returns an array containing two elements: the current state value and a updater function to modify that state value.
Key Takeaways
useStatereturns an array with the current state and its setter function.- Calling the state setter function schedules a re-render of the component with updated values.
Knowledge Check
What does the useState hook return?