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 ruleP1universalStack: React
drycorrectnessreactclean-code
Derive computed values from the real data, not a duplicated copy
When a calculation depends on a value that's also rendered, pass the actual value in rather than hardcoding a duplicate literal that can drift.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetsx
| 1 | const getAnimationDuration = () => { |
| 2 | const title = 'Audio title placeholder'; // duplicates what's rendered |
| 3 | return `${6 + title.length * 0.1}s`; |
| 4 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const getAnimationDuration = (title: string) => `${6 + title.length * 0.1}s`; |
| 2 | // called with the same title that is rendered |
| 3 | <p style={{ animationDuration: getAnimationDuration(title) }}>{title}</p> |
Explanation (EN)
Objašnjenje (HR)