Rules Hub
Code Ruleset
← 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 ruleP1universalStack: React
htmlsemanticsreactlistskeys
Put the anchor inside the list item, not wrapping it
<a> is not permitted as a direct child of <ul>/<ol>; nest the <a> inside each <li>. Also drop the key from inner elements - it belongs only on the outermost mapped element.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | {items.map(i => ( |
| 2 | <a key={i.id} href={i.url}> |
| 3 | <li key={i.id}>{i.title}</li> |
| 4 | </a> |
| 5 | ))} |
Explanation (EN)
An anchor directly beneath the list violates the expected list structure.
Objašnjenje (HR)
Good example
New codetypescript
| 1 | {items.map(i => ( |
| 2 | <li key={i.id}> |
| 3 | <a href={i.url}>{i.title}</a> |
| 4 | </li> |
| 5 | ))} |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
For rendered ul/ol lists, ensure each item is an li and place a mapped-item key on the outermost returned list item.
Exceptions / Tradeoffs (EN)
A separately nested dynamic list has its own key requirement; do not remove keys indiscriminately from all descendants.