About Lesson
The useState
hook is used in functional components to add state to React components. It allows you to declare a state variable and provides a function to update that state.
Key Features:
- State Initialization:
useState
accepts the initial state value as an argument. - State Variable & Setter Function: It returns an array with two elements: the current state value and a function to update it.
- Re-renders: When the state changes, React triggers a re-render of the component with the new state value.
The useState
hook simplifies state management in functional components and enables dynamic, interactive UIs.