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 ruleP2universalStack: React
performancedrycomposition
Compute a value once and share it instead of recomputing
When the same derived value is needed in two sibling places, compute it once at a common parent and pass it down rather than duplicating the calculation.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | // script computes environment |
| 2 | const env = getEnvironment(domain); |
| 3 | // context also computes environment |
| 4 | const env2 = getEnvironment(domain); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | // parent computes once, passes to both |
| 2 | const env = getEnvironment(domain); |
| 3 | <Provider environment={env}><Script environment={env} /></Provider> |
Explanation (EN)
Objašnjenje (HR)