How to Use onClick in Next.js (App Router, 2026)
May 14, 2026Quick answer: I fix onClick in Next.js by adding the
'use client'If you've just moved to the Next.js App Router and your buttons are throwing errors like "Event handlers cannot be passed to Client Component props," you aren't alone.
Handling
onClick[FREE DOWNLOAD] The Next.js App Router Interactivity Cheat Sheet
Stop fighting 'use client' errors. Get the 5 patterns I use to handle state and events without bloating your client bundle. Download the Cheat Sheet Here (Lead Magnet Placeholder)
Why is my Next.js button onClick not working?
In the Next.js App Router, components are Server Components by default. Server Components are rendered on the server and cannot handle browser events like
onClickTo use a button with a click handler, you must add the
"use client";Modern App Router Example
// components/InteractiveButton.tsx "use client"; export default function InteractiveButton() { const handleClick = () => { alert("Button clicked in the browser!"); }; return ( <button onClick={handleClick} className="px-4 py-2 bg-blue-600 text-white rounded-md" > Click Me </button> ); }
How do you pass data from a Server Component to a Client Component?
A common business requirement is fetching data on the server but handling clicks on the client. You should keep your data fetching in a Server Component and pass only the necessary data to an Interactive Client Component.
// app/page.tsx (Server Component) import InteractiveButton from './components/InteractiveButton'; export default function Page() { return ( <main> <h1>Product Dashboard</h1> {/* The button handles interactivity, the page stays a Server Component */} <InteractiveButton /> </main> ); }
How do you navigate to a page on a button click in Next.js?
Don't use
window.location.hrefuseRouternext/navigation"use client"; import { useRouter } from 'next/navigation'; export default function NavButton() { const router = useRouter(); return ( <button onClick={() => router.push('/dashboard')}> Go to Dashboard </button> ); }
Building a Complex Next.js App?
Handling interactivity at scale is hard. I help teams migrate legacy React apps to the Next.js App Router while improving Core Web Vitals. Book a 15-minute consulting discovery call
Conclusion
Mastering
onClickHappy coding!
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [ { "@type": "Question", "name": "How do I fix 'Event handlers cannot be passed to Client Component props' in Next.js?", "acceptedAnswer": { "@type": "Answer", "text": "This error occurs when you try to pass a function like onClick from a Server Component to a Client Component. To fix it, either define the function directly inside a 'use client' component or use Server Actions for logic that doesn't require immediate UI feedback." } }, { "@type": "Question", "name": "Can I use onClick in a Next.js Server Component?", "acceptedAnswer": { "@type": "Answer", "text": "No, Server Components do not support browser events like onClick. You must add the 'use client' directive to the top of your component file to enable interactivity." } }, { "@type": "Question", "name": "What is the best way to navigate on click in Next.js?", "acceptedAnswer": { "@type": "Answer", "text": "The best way to navigate on a button click is using the useRouter hook from 'next/navigation'. This ensures a fast, client-side transition without a full page reload." } } ] } </script>Frequently asked questions
My button is throwing "Event handlers cannot be passed to Client Component props" what's up?
That error means you're trying to pass a function, like your
onClick"use client"Can I just use onClick
directly in a Server Component?
onClickAbsolutely not. Server Components render once on the server. They don't have access to browser JavaScript. For any
onClickuseStateuseEffect"use client";How do I handle navigation on click without window.location.href
?
window.location.hrefDitch
window.location.hrefuseRouternext/navigationrouter.push('/your-path')What's the "Server-to-Client" pattern all about?
It's about keeping your app lean. Fetch data in your Server Component, then pass only the necessary data down to a small, interactive Client Component. This way, the bulk of your page stays on the server, benefiting performance and SEO, while client-side interactivity still functions.