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 ruleP1universalStack: React
reacterror-handlingstateux
Clear a previous error state when an operation succeeds on retry
If an action sets an error on failure, a later successful attempt must reset that error, otherwise stale error UI lingers after recovery.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | const onUpload = async (f) => { |
| 2 | const res = await upload(f); |
| 3 | if (!res.ok) setError(true); // success never clears a prior error |
| 4 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | const onUpload = async (f) => { |
| 2 | const res = await upload(f); |
| 3 | if (!res.ok) { setError(true); return; } |
| 4 | setError(false); // recovered |
| 5 | }; |
Explanation (EN)
Objašnjenje (HR)