Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Always provide a stable key when rendering lists
Give the outermost element or Fragment returned for each React list item a stable sibling-unique key.
Bad example
| 1 | items.map(() => (<><Foo /></>)); |
| 2 | // renderCategory: <div className={style.cat}>...</div> |
Explanation (EN)
Missing or unstable top-level keys can attach state to the wrong item during reconciliation.
Objašnjenje (HR)
Good example
| 1 | items.map(item => <React.Fragment key={item.id}><Foo item={item} /></React.Fragment>); |
Explanation (EN)
The explicit fragment carries a stable identity for the complete returned list item.
Objašnjenje (HR)
Notes (EN)
For React arrays of elements, place a stable sibling-unique key on the outermost returned element or explicit Fragment.
Exceptions / Tradeoffs (EN)
Fixed stateless lists without stable identity may use indices; nested static children do not each need another list key.