Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP2stack specificStack: react
reactkeysclean-code
Put React key only on elements rendered in a list
A key prop is only meaningful on the top-level element produced inside a .map; a standalone element rendered once doesn't need one.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | function Card({ item }) { |
| 2 | return <div key={`card-${item.name}`}>...</div>; // not in a list |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | function Card({ item }) { |
| 2 | return <div>...</div>; |
| 3 | } |
| 4 | // key applied by the caller: items.map(i => <Card key={i.name} item={i} />) |
Explanation (EN)
Objašnjenje (HR)