component identity
How React decides that a component in the new render is the same one as before, so it keeps its state.
In more detail
Identity comes from the component position in the tree, its type and its key. Same position, type and key means state is kept; a different type or key means the old component is unmounted and a new one mounted with fresh state.
Related terms
- key (React) — A special string or number you give to elements in a list so React can tell which item is which between renders.
- mount — When React creates a component for the first time and adds its DOM nodes to the page.
- diffing algorithm — The rules React uses to compare an old element tree with a new one and find what changed.
Taught in
- React Fiber Architecture: Work Units, Priority And Commits — React 19 & Modern Component Architecture
- Keys In Depth: Identity Preservation And Identity Resetting — React 19 & Modern Component Architecture
- Diffing Algorithm: Element Type Shifts And Subtree Tear Down — React 19 & Modern Component Architecture