you-might-not-need-url-state

Detects and fixes URL query-param state anti-patterns in Next.js codebases using nuqs.

29.5k|3.8k|Updated Jan 5, 2025
One-click install
npx skills add https://github.com/simstudioai/sim --skill you-might-not-need-url-state
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: you-might-not-need-url-state
Source: https://github.com/simstudioai/sim/tree/main/.agents/skills/you-might-not-need-url-state
Command: npx skills add https://github.com/simstudioai/sim --skill you-might-not-need-url-state

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Client view-state (tabs, filters, search, sort, pagination, selected entities) often ends up managed inconsistently — read manually via useSearchParams, mutated with hand-built query strings, duplicated into stores, or trapped in local useState — breaking shareability and creating sync bugs. This Skill audits a scope of code for these anti-patterns and optionally applies fixes.

Core Features & Use Cases

  • Anti-pattern detection: Finds manual useSearchParams reads, hand-built query mutations, history.replaceState misuse, URL state mirrored into stores, objects serialized into the URL, and missing Suspense boundaries.
  • Convention-driven fixes: Migrates state to nuqs useQueryState/useQueryStates backed by a co-located search-params.ts, wiring sort via createSortParams + useUrlSort and debounced search via useDebouncedSearchSetter.
  • Decision framework: Routes each piece of state to the correct home — URL for shareable view-state, React Query for remote data, Zustand for high-frequency/socket-synced state, useState for purely local UI.
  • Use Case: Point it at a PR diff or a directory like app/workspace/[workspaceId]/tables/ to audit URL-state usage and automatically refactor violations before merge.

Quick Start

Ask the assistant to analyze the current diff for URL-state anti-patterns and apply fixes using the you-might-not-need-url-state skill.

Frequently Asked Questions about you-might-not-need-url-state

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix useSearchParams anti-patterns in Next.js?

Replace manual useSearchParams().get() reads with nuqs useQueryState or useQueryStates bound to a co-located search-params.ts file. Read-once auth tokens like callbackUrl or invite codes are exempt and can stay on useSearchParams.

When should state go in the URL versus useState or Zustand?

Shareable view-state like tabs, filters, sort, pagination, and selected-entity ids belongs in the URL. High-frequency, large, ephemeral, or socket-synced state belongs in Zustand, and purely local UI state stays in useState.

How do I add debounced search to URL query params with nuqs?

Use the shared useDebouncedSearchSetter hook rather than wiring limitUrlUpdates inline or mirroring the input in local useState. Never write a trimmed value to the param controlling the input; trim on read instead.

Why does useQueryState require a Suspense boundary in Next.js?

Next.js requires a Suspense wrapper around any component calling useSearchParams, which nuqs hooks use internally. Pages newly adopting useQueryState must add a Suspense boundary with a real-chrome fallback to avoid build errors.

Can I run the analysis without applying changes?

Yes, pass fix=false to only propose fixes without modifying code. The default scope is your current changes, but you can target a diff to main, a PR number, a directory, or the whole codebase.