Skip to main content

Overview

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.

Why Use withUniwind?

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.

Problem

Solution

Automatic Prop Mapping

withUniwind automatically maps props based on their names. Any prop containing style or color in its name is automatically mapped.
No manual mapping needed! The style prop is automatically mapped to className, and color-related props get their own *ClassName variants.

Automatic Mappings

Here are some examples of how props are automatically mapped:
Original PropMapped ClassName PropExample Usage
styleclassName<Component className="p-4" />
colorcolorClassName<Component colorClassName="accent-red-500" />
backgroundColorbackgroundColorClassName<Component backgroundColorClassName="accent-blue-500" />
borderColorborderColorClassName<Component borderColorClassName="accent-gray-300" />
tintColortintColorClassName<Component tintColorClassName="accent-green-500" />

Example: Using Auto-Mapped Color Props

Custom Prop Mapping

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.

How Mapping Works

The mapping object structure is:
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

Example: Mapping a Width Prop

Some components accept a width prop as a number or string, not a style object. Here’s how to map it:

Example: Mapping a Size Prop

Example: SVG Stroke and Fill

SVG components often use stroke and fill props that accept color values:
Use accent-* classes when you need to extract a color value. The accentColor style property is specifically designed for this purpose in Uniwind.

Mapping Entire Style Objects

If you omit styleProperty, the entire resolved style object is passed to the target prop:

Third-Party UI Components

API Reference

Function Signature

Parameters

Component
React.ComponentType
required
The React component to wrap with className support.
mappings
PropMappings
Optional custom prop mappings. Each mapping defines how to convert a className prop to a component prop.Mapping structure:

Return Value

StyledComponent
React.ComponentType
A wrapped component that accepts className and auto-generated *ClassName props, in addition to all original component props.

Best Practices

Create reusable styled components: Define your wrapped components in a separate file and export them for reuse throughout your app.
Performance consideration: Wrap components at the module level (outside your component functions) to avoid recreating the wrapper on every render.

useResolveClassNames

Convert classNames to style objects at runtime

Third-Party Components

Learn about styling third-party component libraries