Next.js Discord

Discord Forum

Export variants with cn

Answered
Japanese Bobtail posted this in #help-forum
Open in Discord
Avatar
Japanese BobtailOP
Hi there. Is it possible to export the button variants (const variants) with cn? I want to prevent the multiple use of cn outside the component. My usecase is:

´import { cn } from '../Utils';
import { Variants } from '../Button';

<Link
href='...'
className={cn(Variants({ ... }))}
>...</Link>´

Here you find the button component:
https://paste.gg/p/anonymous/5afc2a4615f94214bd76aff3ffd2443b
Answered by B33fb0n3
Use it like className={cn(buttonVariants())}. If needed you can then also add more classes to it: className={cn(buttonVariants(), "w-full")}
View full answer

2 Replies