Reconciliation - alexanderteplov/computer-science GitHub Wiki
The algorithm React uses to diff one tree with another to determine which parts need to be changed. It is triggered before the re-rendering process starts.
To transform one tree into another, the "state of the art" algorithms have a complexity in the order of O(n3).
React implements a heuristic O(n) algorithm based on two assumptions:
- Two elements of different types will produce different trees.
- The developer can hint at which child elements may be stable across different renders with a key prop.
Conclusions:
- return element of the same type from the same component (to avoid the whole child tree destruction)
- use stable unique keys