Skip to content

Commit 4219a74

Browse files
Refactor Button component to use React 19 ref pattern
- Remove React.forwardRef wrapper as per React 19 guidelines - Add optional ref prop to ButtonProps interface with type React.Ref<HTMLButtonElement> - Convert Button to normal function component that extracts ref from props - Pass ref directly to rendered component (Comp) - Maintain all existing functionality while aligning with modern React patterns This change follows React 19's simplified ref handling where refs are treated as regular props instead of requiring forwardRef.
1 parent cd8e40c commit 4219a74

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

packages/components/src/ui/button.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,20 @@ const buttonVariants = cva(
3434

3535
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
3636
asChild?: boolean;
37+
ref?: React.Ref<HTMLButtonElement>;
3738
}
3839

39-
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
40-
({ className, variant, size, asChild = false, ...props }, ref) => {
41-
const Comp = asChild ? Slot : 'button';
42-
return (
43-
<Comp
44-
className={cn(buttonVariants({ variant, size, className }))}
45-
data-slot="button"
46-
ref={ref}
47-
{...props}
48-
/>
49-
);
50-
}
51-
);
40+
export function Button({ className, variant, size, asChild = false, ref, ...props }: ButtonProps) {
41+
const Comp = asChild ? Slot : 'button';
42+
return (
43+
<Comp
44+
className={cn(buttonVariants({ variant, size, className }))}
45+
data-slot="button"
46+
ref={ref}
47+
{...props}
48+
/>
49+
);
50+
}
5251

5352
Button.displayName = 'Button';
5453

0 commit comments

Comments
 (0)