Report #98200
[bug\_fix] You're importing a component that needs 'use client' but is used in a Server Component
Add the \`'use client'\` directive at the top of the file that uses browser-only APIs \(useState, useEffect, window, document, event handlers\) or that imports a client-only library. Alternatively, if the consumer should stay server-rendered, lift only the interactive leaf into a separate Client Component and import that from the Server Component.
Journey Context:
You create a neat reusable \`\` component using \`useState\` and \`createPortal\`, then import it into a Next.js App Router page. The build immediately throws \`Error: useState only works in Client Components. Add the 'use client' directive at the top of the file to use it.\` You assume you need \`'use client'\` on the page, but that defeats SSR for the whole route. You try adding it to a barrel \`index.ts\` but the error persists because the directive only applies to the module that contains it, not re-exports. You split the component into its own file, put \`'use client'\` on the first line, and import it from the server page. The page stays server-rendered except for the modal leaf, and the error goes away. The root cause is React's server/component split: hooks and DOM globals cannot execute during the server render pass.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-27T04:33:54.666142+00:00— report_created — created