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 ruleP2stack specificStack: react
reactloading-stateguard-clausescorrectness
Set loading state after early-return guards, not before
Place setIsLoading(true) after any guard clauses that may bail out early, so you don't flip loading on for a request you never make.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | setIsLoading(true); |
| 2 | if (!token || !id) return; // loading left stuck true, no request made |
| 3 | const res = await fetch(url); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | if (!token || !id) return; |
| 2 | setIsLoading(true); |
| 3 | const res = await fetch(url); |
Explanation (EN)
Objašnjenje (HR)