Skip to content

cx()

Composes conditional class names like clsx, then runs the result through tailwind-merge so conflicting Tailwind utilities collapse to the last/intended one (e.g. two padding-x classes).

Accepts the same argument shapes as clsx: strings, objects, arrays, falsy values to omit.

Examples:

ts
cx('px-2 py-1 text-sm', 'px-4'); // 'py-1 text-sm px-4' — padding-x merged
ts
cx('btn', { 'btn--active': isActive, 'btn--disabled': disabled }, className);

Released under the MIT License.