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 installso versions match your SDK.
init adds it for you.
Usage
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
cnteaches it the type scale:cn('text-body', 'text-headline')givestext-headline, andcn('text-body', 'text-muted-foreground')keeps both. If you add your own text sizes, add them tocntoo.
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 on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.