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 ruleP2universalStack: react
reactstateuxhooks
Reset transient UI state when a component is hidden
Clear hover/selection state when a popover or panel closes so it reopens in a clean state.
PR: hegnar-components · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codetsx
| 1 | const [hoveredCell, setHoveredCell] = useState(null); |
| 2 | // never reset; reopening shows last hover |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | useEffect(() => { |
| 2 | if (!isVisible) setHoveredCell(null); |
| 3 | }, [isVisible]); |
Explanation (EN)
Objašnjenje (HR)