Recall & Review
beginner
What is the purpose of the
useState hook in React?The
useState hook lets you add state to functional components. It returns a state variable and a function to update it.Click to reveal answer
intermediate
How do you update state based on the previous state in React?
You pass a function to the state updater that receives the previous state and returns the new state. This ensures you work with the latest state.
Click to reveal answer
beginner
Why should you never modify state variables directly in React?
Directly changing state variables can cause bugs because React won't know the state changed and won't update the UI properly.
Click to reveal answer
beginner
What happens when you call the state updater function returned by
useState?React schedules a re-render of the component with the new state value, updating the UI to reflect the change.
Click to reveal answer
intermediate
How can you update multiple state variables in React?
You call each state updater function separately. Each call schedules a re-render with the updated state values.
Click to reveal answer
What does the
useState hook return?✗ Incorrect
The
useState hook returns an array with the current state and a function to update that state.How do you update state based on the previous state?
✗ Incorrect
Passing a function to the updater ensures you get the latest previous state to calculate the new state.
What happens if you modify state directly without using the updater?
✗ Incorrect
React relies on the updater function to know when to re-render. Direct changes are ignored.
Which of these is the correct way to update a counter state?
✗ Incorrect
Both calling setCount with count + 1 or with a function updating previous state are valid ways.
Can you update multiple state variables at once with one updater function?
✗ Incorrect
Each state variable has its own updater function; you call each one separately to update multiple states.
Explain how to update state in React using the
useState hook.Think about how you tell React to change something and show it again.
You got /4 concepts.
Why is it important to avoid modifying state variables directly in React?
Imagine changing something behind React's back.
You got /4 concepts.