Skip to content

Instantly share code, notes, and snippets.

@codemile
Created January 2, 2025 16:48
Show Gist options
  • Save codemile/340412f5cd47fdbf05b5110d82fd6bb9 to your computer and use it in GitHub Desktop.
Save codemile/340412f5cd47fdbf05b5110d82fd6bb9 to your computer and use it in GitHub Desktop.
Utility function to merge Tailwind classes with clsx and twMerge, plus a TypeScript type for props with className.
import {type ClassValue, clsx} from 'clsx';
import {twMerge} from 'tailwind-merge';
export type PropsWithClassName<P = unknown> = P & {
className?: ClassValue | undefined;
};
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment