Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use CSS custom properties for values shared between CSS and JS
SCSS variables are build-time macros and cannot be read at runtime. For a value needed in CSS and also via the JS style prop, define a CSS custom property (var) so there is one source of truth.
Bad example
| 1 | // SCSS only; the same color is then hard-coded again in JS |
| 2 | $accent: #3498db; |
Explanation (EN)
Hardcoding a second copy in JavaScript can diverge from the stylesheet's design value.
Objašnjenje (HR)
Good example
| 1 | :root { --accent: #3498db; } |
| 2 | /* CSS: color: var(--accent); JS: style={{ color: 'var(--accent)' }} */ |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
When one runtime/theme value must be used by both CSS declarations and an element's style prop, reuse a scoped CSS custom property or the existing token export pipeline.
Exceptions / Tradeoffs (EN)
Sass can export generated values through build tooling; custom properties are not the only sharing mechanism. JS needing a numeric computed value may require getComputedStyle and unit handling.