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-formvalidationerror-handling
Set server errors through the submit handler's form methods
Use the form library's setError from the submit callback (often provided as a second argument) instead of separate component state for server-side errors.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const [serverError, setServerError] = useState(''); |
| 2 | const handleSubmit = async (data) => { |
| 3 | const ok = await api.signIn(data); |
| 4 | if (!ok) setServerError('Incorrect email or password'); |
| 5 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const handleSubmit = async (data, methods: UseFormReturn<FormFields>) => { |
| 2 | const ok = await api.signIn(data); |
| 3 | if (!ok) { |
| 4 | methods.setError('password', { type: 'server', message: 'Incorrect email or password' }); |
| 5 | } |
| 6 | }; |
Explanation (EN)
Objašnjenje (HR)