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 ruleP1stack specificStack: react
ssrhydrationresponsivereact
Keep user-agent based device detection on the server to avoid hydration re-renders
Detect device type from the user agent server-side so server and client render the same markup and you avoid an extra re-render.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | 'use client'; |
| 2 | export const useBreakpoint = () => { |
| 3 | const [isMobile, setIsMobile] = useState(false); |
| 4 | useEffect(() => setIsMobile(window.innerWidth < 768), []); |
| 5 | return { isMobile }; |
| 6 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | // no 'use client' — resolve from user agent on the server |
| 2 | export const useBreakpoint = () => { |
| 3 | const ssrMatchMedia = (query) => ({ matches: matchFromUserAgent(query) }); |
| 4 | // server-rendered state matches client, no double render |
| 5 | }; |
Explanation (EN)
Objašnjenje (HR)