React · Middle · Question 1 of 75

When does React preserve a component's state between renders?

Explanation

State is tied to a position in the UI tree, not to a variable. If a different type renders in the same place (<input> instead of <textarea>, another component), the subtree is recreated and state is lost. That's why you must not declare components inside other components: each render creates a new type.

Further reading

Problem with a question

React · Middle · question 1

Test yourself

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

Take this quiz