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).
Use shared breakpoint constants instead of magic pixel widths
Reference a single shared breakpoint definition rather than inlining magic pixel values for responsive checks.
Bad example
| 1 | const isMobile = () => typeof window !== 'undefined' && window.innerWidth < 768; |
Explanation (EN)
An inline 768 can disagree with the breakpoint used elsewhere (and with the CSS), causing the JS and CSS notions of 'mobile' to diverge.
Objašnjenje (HR)
Ubaceni 768 se moze razlikovati od breakpointa koristenog drugdje (i od CSS-a), pa se JS i CSS pojam 'mobilnog' razilaze.
Good example
| 1 | import { BREAKPOINTS } from 'styles/settings/breakpoints'; |
| 2 |
|
| 3 | const isMobile = () => window.innerWidth < BREAKPOINTS.mobile; |
Explanation (EN)
A single source of truth for breakpoints keeps responsive logic consistent between JS and SCSS and makes changes one-line.
Objašnjenje (HR)
Jedan izvor istine za breakpointe cuva responzivnu logiku konzistentnom izmedu JS-a i SCSS-a i cini promjene jednom linijom.
Notes (EN)
Confirm the value matches the breakpoint already agreed on for the product (the review flagged 768 vs an existing 640).
Bilješke (HR)
Provjeri da vrijednost odgovara breakpointu vec dogovorenom za proizvod (review je upozorio na 768 nasuprot postojecih 640).