SwipeUI
DocsHooks & utilities

cn

Joins class names and resolves conflicting Tailwind utilities, including the SwipeUI type scale.

Joins conditional class names and resolves conflicting Tailwind utilities, including the SwipeUI type scale.

Free (MIT)Version 1.3.0Released 20 Nov 2026iOS and Android

When to use it

  • Merge a component default with caller-supplied Tailwind classes.

When not to use it

  • Use ordinary strings when there are no conditional or conflicting utilities.

Installation

Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.

npx @swipeui/cli add cn
  • Adds components/swipeui/lib/cn.ts.
  • Installs clsx, tailwind-merge. In Expo apps it uses npx expo install so versions match your SDK.

init adds it for you.

Usage

components/route-row.tsx
import { cn } from '@/components/swipeui/lib/cn';

<View className={cn('rounded-md bg-card p-4', selected && 'bg-accent', className)} />;

It joins conditional classes with clsx, then lets later utilities win with tailwind-merge: cn('px-4', 'px-2') gives px-2.

Gotchas

  • tailwind-merge doesn't know custom sizes, so cn teaches it the type scale: cn('text-body', 'text-headline') gives text-headline, and cn('text-body', 'text-muted-foreground') keeps both. If you add your own text sizes, add them to cn too.

Accessibility

  • This helper adds no accessibility behavior; the rendered component owns its semantics.

Motion

  • Static on its own; any movement comes from the parent that animates it.
  • No custom movement is configured by this item.

Performance

  • Merges classes synchronously and creates no native views.

Notes for AI

  • Use cn(defaultClasses, className) so the caller can override defaults.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items

On this page