Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Avoid explicitly passing a prop value equal to the library default
Omit props whose value matches the library/API default; let the default apply instead of restating it at the call site.
Bad example
| 1 | // Library already portals to document.body when `container` is undefined |
| 2 | <Portal container={portalTarget ?? document.body}> |
| 3 | {children} |
| 4 | </Portal> |
Explanation (EN)
Passing `document.body` restates a value the library already uses by default, adding noise without changing behavior.
Objašnjenje (HR)
Prosljeđivanje `document.body` ponavlja vrijednost koju biblioteka već koristi prema zadanom, dodajući šum bez promjene ponašanja.
Good example
| 1 | // Pass undefined to fall back to the library default (document.body) |
| 2 | <Portal container={portalTarget ?? undefined}> |
| 3 | {children} |
| 4 | </Portal> |
Explanation (EN)
Letting the prop fall through to the library default keeps the call site minimal and avoids coupling to an internal default that the library owns.
Objašnjenje (HR)
Pustiti da prop padne na zadanu vrijednost biblioteke drži poziv minimalnim i izbjegava vezivanje uz internu zadanu vrijednost kojom upravlja biblioteka.
Exceptions / Tradeoffs (EN)
If naming the default value materially improves reader intent or guards against a future default change, an explicit value can be a deliberate, documented choice.
Iznimke / Tradeoffi (HR)
Ako imenovanje zadane vrijednosti bitno poboljšava jasnoću namjere ili štiti od buduće promjene zadane vrijednosti, eksplicitna vrijednost može biti namjeran, dokumentiran izbor.