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: JavaScript/TypeScript, React
formsstatecorrectness
Reset a cleared optional selection to null, not a stale value
When the user deselects an optional field, set the form value to null so the cleared state is represented accurately.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | // keeps last value even after user unselects |
| 2 | setValue('category', selectedCategory); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | setValue('category', selectedCategory ?? null); |
Explanation (EN)
Objašnjenje (HR)