React · Middle · Question 1 of 75
When does React preserve a component's state between renders?
- ✓Correct answer: As long as the same component type stays at the same position
- 2As long as the component's props haven't changed by reference
- 3Always, until the whole page is reloaded
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.