← React Beginner Questions - Set 4 Q37
React Beginner Questions - Set 4
The diffing pass. Its practical consequence: element type decides reuse, and `key` decides which sibling is which.
// Same type -> React updates in place, state survives
{isOn ? <Counter theme="light" /> : <Counter theme="dark" />}
// Different type -> unmount + mount, state is lost
{isOn ? <Counter /> : <div><Counter /></div>}
// Same component, different key -> treated as a different element
{items.map(i => <Row key={i.id} item={i} />)}
// Swapping the key resets the component on purpose
<Profile key={userId} userId={userId} />