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, react-hook-form
reactformsreact-hook-formstateduplication
Use the form library's built-in error state instead of custom state
Rely on the form library's error/validation state rather than maintaining parallel useState flags for the same concern.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const [hasServerError, setHasServerError] = useState(false); |
| 2 | const hasError = hasServerError || !!errorMessage; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const { formState } = useFormContext(); |
| 2 | const hasError = !!formState.errors[name]; |
Explanation (EN)
Objašnjenje (HR)