Code snippets
cn utility function
A utility function for merging Tailwind classes.
Introduction
The cn
utility function is a simple implementation of the clsx
and twMerge
functions from the clsx
and tailwind-merge
packages. It allows you to merge Tailwind classes in a type-safe way.
Installation
To use the cn
utility function, you need to install the clsx
and tailwind-merge
packages:
Code
/src/utils/cn.ts
or /src/lib/utils.tsx
Usage
Here's an example of how to use the cn
utility function:
In this example, the cn
function is used to create a class name based on the baseClass
and activeClass
variables. The isActive
state variable is used to conditionally apply the activeClass
to the class name.