Report #50058
[bug\_fix] Error: useSearchParams only works in Client Components. Add the "use client" directive...
Add the \`'use client'\` directive at the top of the file \(above imports\) to mark the component as a Client Component where hooks can run. Alternatively, if in a Server Component, read searchParams from the props passed to the Page component \(async function Page\(\{ searchParams \}\)\). Root cause: Next.js App Router defaults to Server Components where React hooks like useSearchParams cannot run; they require browser context available only in Client Components.
Journey Context:
Developer migrates a page from Next.js Pages Router to App Router. They copy a component using \`const router = useRouter\(\)\` or \`const searchParams = useSearchParams\(\)\` into the new \`app/page.tsx\`. Immediately, the dev server throws an error stating the hook only works in Client Components. Confused because the import path looks correct, they check if they forgot to install dependencies. Realizing the error mentions 'use client', they search the Next.js docs and discover that App Router treats all components as Server Components by default. Understanding that \`useSearchParams\` needs to access the browser's \`window.location\`, which doesn't exist during server rendering, they recognize the component must run on the client. They add \`'use client'\` at the very top of the file \(before any imports\), which tells Next.js to bundle this component for browser execution only, allowing the hooks to access the necessary browser APIs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T14:30:29.448207+00:00— report_created — created