Reconciliation
一句话解释
Reconciliation 是处理 React uses 到 compare 上一个 and 下一个虚拟 DOM 树 and determine minimal 设置的 DOM 更改需要.
用大白话说
Reconciliation is React's algorithm for updating the real DOM efficiently. When state or props change, React renders the component to produce a new virtual DOM tree. It then walks both the old and new trees simultaneously, comparing nodes.
The algorithm makes assumptions to stay fast: (1) two elements of different types produce completely different trees, so React unmounts the old and mounts the new; (2) elements with the same type and key are considered the same and their props are updated in place. This is why the 键 prop is important in lists — it helps React match items across renders.
After diffing, React applies the computed mutations to the real DOM in a single batch. This process is what makes React fast: instead of re-rendering the entire page, only the changed parts are updated.
示例
// Before: <li key="a">Apple</li>
// After: <li key="a">Apple</li><li key="b">Banana</li>
// React sees key "a" matches, keeps it, and only inserts the new "b" item.因为键 是 stable, React knows 首先项 didn't 更改 and 仅添加新 其次项, 而不是 re-渲染整个列表.
相关术语
相关资源
相关课程
- React Overview
理解如何 React 更新 DOM.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。