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
reactcompatibilitylibraryversioning
Don't reach for newer framework APIs that break supported versions
If a library must support an older major (e.g. React 17), avoid version-gated APIs like createRoot directly; feature-detect with a dynamic import fallback so older consumers still work.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | import { createRoot } from 'react-dom/client'; // breaks React 17 consumers |
| 2 | createRoot(container).render(<App />); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | export async function createRoot(container: Container) { |
| 2 | try { |
| 3 | const { createRoot } = await import('react-dom/client'); |
| 4 | return createRoot(container); |
| 5 | } catch { |
| 6 | const { render, unmountComponentAtNode } = await import('react-dom'); |
| 7 | return { render: (c) => render(c, container), unmount: () => unmountComponentAtNode(container) } satisfies Root; |
| 8 | } |
| 9 | } |
Explanation (EN)
Objašnjenje (HR)