Recall & Review
beginner
What is the purpose of the
useState hook when handling input fields in React?The
useState hook stores the current value of the input field and allows React to update the UI when the input changes.Click to reveal answer
beginner
How do you update the state when a user types in an input field?
You use an
onChange event handler that calls the state setter function with the new input value.Click to reveal answer
intermediate
What does it mean for an input field to be a "controlled component" in React?
A controlled component is an input element whose value is controlled by React state, so the displayed value always matches the state.
Click to reveal answer
beginner
Why should you use the
value attribute on input fields in React?Using the
value attribute links the input's displayed value to React state, ensuring the UI updates correctly and stays in sync.Click to reveal answer
intermediate
What is a common mistake when handling input fields that can cause the input to become uneditable?
Not updating the state on
onChange can cause the input to be stuck because React controls the value but never changes it.Click to reveal answer
Which React hook is commonly used to store the value of an input field?
✗ Incorrect
The useState hook is used to store and update the input field's value.
What event handler updates the state when a user types in an input field?
✗ Incorrect
The onChange event handler captures input changes and updates the state.
What happens if you set the input's value from state but do not update the state on input change?
✗ Incorrect
Without updating state on change, React controls the input value but never changes it, making it uneditable.
What is a controlled input in React?
✗ Incorrect
Controlled inputs have their value managed by React state to keep UI and data in sync.
Why is it important to link the input's value to React state?
✗ Incorrect
Linking value to state ensures the UI shows the current data and updates correctly.
Explain how to create a controlled input field in React and why it is useful.
Think about how React controls the input's displayed value.
You got /4 concepts.
Describe a common mistake when handling input fields in React and how to fix it.
What happens if React controls the input but never changes the value?
You got /3 concepts.