Report #95035
[bug\_fix] Event handlers can only be used in Client Components \(adding onClick to Server Component\)
Extract the interactive element into a separate file with the 'use client' directive, or add 'use client' to the current file if the whole component needs interactivity, passing Server Components as children to preserve SSR.
Journey Context:
Developer adds an onClick handler to a button inside a page.tsx \(Server Component\) in the Next.js App Router. Immediately, the TypeScript compiler or Next.js dev server shows the error: 'Event handlers can only be used in Client Components. Add the "use client" directive'. The developer is confused because they thought React components always supported onClick. They learn that Server Components execute on the server and cannot attach event listeners to DOM elements. The solution is to extract the interactive button into a separate Button.tsx file with 'use client' at the top, then import it into the Server Component page. Alternatively, if the whole page needs interactivity, add 'use client' to page.tsx, though this forfeits Server Component benefits like zero JS bundle size. The optimal pattern is to keep Server Components for data fetching and pass them as children to Client Component wrappers for interactivity.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:05:49.684142+00:00— report_created — created