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).
Default optional props once at destructuring, not at each use
Set defaults for optional props in the parameter destructuring rather than coalescing (?? fallback) at each call site.
Bad example
| 1 | const Row = ({ title, isNew }: RowProps) => { |
| 2 | const { isAnimating } = useAnimation(isNew ?? false); |
| 3 | // ...isNew ?? false repeated wherever it's read |
| 4 | }; |
Explanation (EN)
Coalescing the fallback at every usage is repetitive and risks inconsistent defaults if one site is missed.
Objašnjenje (HR)
Ponavljanje fallbacka na svakom mjestu koristenja je repetitivno i riskira nekonzistentne zadane vrijednosti ako se neko mjesto propusti.
Good example
| 1 | const Row = ({ title, isNew = false }: RowProps) => { |
| 2 | const { isAnimating } = useAnimation(isNew); |
| 3 | }; |
Explanation (EN)
A single default in the destructuring guarantees the prop is always defined downstream, removing repeated nullish coalescing.
Objašnjenje (HR)
Jedna zadana vrijednost u destrukturiranju jamci da je prop uvijek definiran nizvodno, uklanjajuci ponovljeno nullish coalescing.