How React Uses the key Attribute Internally
Based on the stable React v19.2.8, the article explains what happens to the key attribute written in JSX. It is not rendered as a DOM attribute and is not a normal prop: reading props.key in development mode triggers a React warning. Instead, React stores the key in a ReactElement[1] and then copies it to a Fiber[2] node.
The article then describes reconciliation[3] in React. React first compares keys and then element types to decide whether an old Fiber can be reused. A matching key alone does not guarantee reuse: if the key matches but the type differs, the old node is deleted and a new one is created.
For lists, the article describes three stages: comparing old and new nodes from left to right, checking which side has finished first, and looking up remaining old Fibers in a Map. In that Map, each Fiber is stored under its key, or under its index if it has no key.
Discussion
Commenters mostly praise the article for its clear writing and ask for more posts. Several comments consist only of emoji or the same short phrase repeated.
Sources
-
CNJuejin ZH
由 key 引发的思考



