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 RefObject for object refs; reserve React.Ref for callback-ref flexibility
React.Ref allows both object and callback refs, forcing you to check the type before reading .current. Use React.RefObject<T | null> unless you actually need to accept callback refs.
Bad example
| 1 | inputRef: React.Ref<HTMLInputElement>; // now .current isn't guaranteed |
Explanation (EN)
A union of callback and object refs cannot be read as .current without narrowing.
Objašnjenje (HR)
Good example
| 1 | inputRef: React.RefObject<HTMLInputElement | null>; // .current is available |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Use an object-ref type for an API that explicitly reads current; use the general React.Ref type for forwarding to JSX when both callback and object refs are supported.
Exceptions / Tradeoffs (EN)
Do not narrow a public forwarding API merely to avoid handling a union internally. React type versions differ in mutability and nullable generic conventions.