Docs are incorrect in showing how to call CN function
Describe the bug Calling...
cn('bg-red-500', 'text-white');
will not work, and results in a return of a function, not the result, as the docs show.
In order to work, you must write it like this:
cn('bg-red-500', 'text-white')({ twMerge: true });
To Reproduce Steps to reproduce the behavior:
- Install 3.1
- Run
console.log(cn('bg-red-500', 'text-white')) - See results in console
Expected behavior It should behave as the docs describe.
Just ran across this myself – I almost wonder if this is intentional, because IMO it's not a great API to pass these settings. Also, based on the docs it seems that cn is supposed to automatically use/detect twMerge, whereas cnBase just merges without it 🤔
Just ran across this myself – I almost wonder if this is intentional, because IMO it's not a great API to pass these settings. Also, based on the docs it seems that
cnis supposed to automatically use/detect twMerge, whereascnBasejust merges without it 🤔
Yea it seems that cn should be able to be called alone without the {twMerge} property passed.
Any update on this?
For anyone who is wondering how to do this, just wrap it
import { type ClassValue, cn as cnTV } from "tailwind-variants";
export function cn(...args: ClassValue[]) {
return cnTV(args)({ twMerge: true });
}
so now you can do
<div className={cn("bg-red-500")} />
For anyone who is wondering how to do this, just wrap it
import { type ClassValue, cn as cnTV } from "tailwind-variants";
export function cn(...args: ClassValue[]) { return cnTV(args)({ twMerge: true }); } so now you can do
Yea I ended up doing something similar :)
Fixed 🙌🏼, thanks for reporting it, will be available on v3.1.0