From 98eba8f7cda477ab801dab380f249acf41a814da Mon Sep 17 00:00:00 2001 From: Kane Wang Date: Fri, 3 May 2024 20:24:15 +0800 Subject: [PATCH] fix Unused constant Comp --- src/components/ui/button.tsx | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx index 19a0257..467e589 100644 --- a/src/components/ui/button.tsx +++ b/src/components/ui/button.tsx @@ -3,6 +3,7 @@ import { cva, type VariantProps } from "class-variance-authority"; import * as React from "react"; import { cn } from "@/lib/utils"; +import { createElement } from "react"; const buttonVariants = cva( "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 no-underline", @@ -41,17 +42,13 @@ export interface ButtonProps } const Button = React.forwardRef( - ({ className, variant, size, asChild = false, ...props }, ref) => { - const Comp = asChild ? Slot : "button"; - return ( - - ); - }, + ({ className, variant, size, asChild = false, ...props }, ref) => + createElement(asChild ? Slot : "button", { + type: "button", + className: cn(buttonVariants({ variant, size, className })), + ref, + ...props, + }), ); Button.displayName = "Button";