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: Next.js
url-statenuqsrefactor
Prefer a query-state library over manual URLSearchParams plumbing
For URL-synced state, use a dedicated query-state hook (e.g. nuqs useQueryState) instead of hand-rolling useState + useSearchParams + router.push; it removes boilerplate and supports push history.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codetsx
| 1 | const [sortField, setSortField] = useState(searchParams.get('sortBy') || 'ranking'); |
| 2 | const params = new URLSearchParams(searchParams.toString()); |
| 3 | params.set('sortBy', field); |
| 4 | router.push(`?${params}`); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const [sortField, setSortField] = useQueryState( |
| 2 | 'sortBy', |
| 3 | parseAsString.withDefault('ranking').withOptions({ history: 'push' }) |
| 4 | ); |
Explanation (EN)
Objašnjenje (HR)