Next.js Discord

Discord Forum

Client Button and Server Button

Answered
American Crow posted this in #help-forum
Open in Discord
American CrowOP
I am starting to work on a project and trying to understand it.
The author has two components of Buttons.
One is using the use client directive in the begging and is basically just a wrapper for the the other button.
Other than that the Client Button seems to have no additional purpose

Client-Button.tsx
"use client"

import { cn } from "@/lib/utils"
import { Button, type ButtonProps } from "@/components/ui/button"

interface ClientButtonProps extends ButtonProps {}

export function ClientButton({ className, ...props }: ClientButtonProps) {
  return <Button className={cn(className)} {...props}></Button>
}


Why would you do something like that ? I cant really think of use cases when to use one over the other?
Answered by Ray
use the one with 'use client' when you need to use event handler eg, onClick
View full answer

3 Replies