State Management · Middle · Question 2 of 75

How do you reset a form component's state when the selected user changes?

Explanation

A different key makes React treat it as a new component: old state is dropped and the initial values apply. A resetting effect first renders stale data and then fixes it - an extra render and a visible flash.

Further reading

Problem with a question

State Management · Middle · question 2

Test yourself

Take the State Management · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz