The withUniwind higher-order component (HOC) wraps any React Native component to add className prop support. This is essential for using third-party components with Uniwind’s Tailwind-based styling system.
Many popular React Native libraries export components that don’t natively support the className prop. Instead, they accept the traditional style prop. The withUniwind wrapper bridges this gap, allowing you to use Tailwind classes with any component.
Some third-party components work out of the box! Libraries like React Native Reanimated that are built on top of React Native’s core components (View, Text, etc.) automatically support className without wrapping. You only need withUniwind when the underlying implementation uses custom native components or doesn’t forward the style prop properly.
import { SafeAreaView } from 'react-native-safe-area-context';// ❌ This won't work - SafeAreaView is a third-party component<SafeAreaView className="flex-1 bg-background"> {/* content */}</SafeAreaView>
import { withUniwind } from 'uniwind'import { SafeAreaView } from 'react-native-safe-area-context';const StyledSafeAreaView = withUniwind(SafeAreaView);// ✅ This works - we've wrapped the component with withUniwind<StyledSafeAreaView className="flex-1 bg-background"> {/* content */}</StyledSafeAreaView>
import { withUniwind } from 'uniwind'import { ActivityIndicator } from 'react-native-activity-indicator'const StyledActivityIndicator = withUniwind(ActivityIndicator)// Use colorClassName instead of the color prop<StyledActivityIndicator colorClassName="accent-blue-500 dark:accent-blue-300" size="large"/>
For advanced use cases, you can define custom mappings to map className props to component props. This is useful for components with non-standard prop names like width, size, fill, or stroke.
withUniwind(Component, { targetProp: { // The component's original prop name fromClassName: 'myClassName', // The className prop you'll use in JSX styleProperty: 'width', // (Optional) Which CSS property to extract },})
Understanding the structure:
Object key (targetProp) → The prop that the component actually receives
fromClassName → The new className prop you’ll write in your JSX
styleProperty → Which CSS property value to extract and pass to the target prop
Optional custom prop mappings. Each mapping defines how to convert a className prop to a component prop.Mapping structure:
{ [targetProp: string]: { fromClassName: string, // The className prop name to create styleProperty?: string // Optional CSS property to extract (omit to use entire style) }}