React · Senior · Question 45 of 75
How does key on a wrapper component differ from key inside a list?
- ✓Correct answer: Mechanically it doesn't: changing
keyalways means a new instance with new state - 2Outside lists,
keyis ignored and serves only as a hint for the linter - 3Outside lists,
keycaches the component instead of recreating it
Explanation
key is part of a component's identity anywhere. In a list it matches items between renders; outside a list it's used to explicitly reset state (<Chat key={contactId} />). The key must be unique among siblings, not globally.