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
reacttypescriptrefstype-inference
Let useRef infer its type instead of annotating a written ref as RefObject
RefObject types current as readonly; if you assign to ref.current, don't annotate it as RefObject — let useRef infer a mutable ref type from its initial value.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | const portfoliosRef: RefObject<Portfolio[]> = useRef(portfolios); |
| 2 | portfoliosRef.current = portfolios; // RefObject.current is readonly |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | const portfoliosRef = useRef(portfolios); // inferred mutable type |
| 2 | portfoliosRef.current = portfolios; |
Explanation (EN)
Objašnjenje (HR)