Overview
TheuseResolveClassNames
hook converts Tailwind class names into valid React Native style
objects. This is useful when working with components or libraries that don’t support the className
prop directly, such as react-navigation
theme configuration or third-party components that can’t be wrapped in withUniwind
.
This hook should be used rarely. For most use cases, prefer using the
className
prop on Uniwind-wrapped components.When to Use This Hook
UseuseResolveClassNames
when you need to:
- Configure libraries that accept style objects (e.g.,
react-navigation
themes) - Pass styles to third-party components that only accept
style
props (and can’t be wrapped inwithUniwind
) - Generate style objects dynamically for special use cases
- Work with legacy code that requires style objects
Prefer these alternatives when possible:
- For React Native components: Use the
className
prop directly. See Components. - For third-party components: Wrap them with
withUniwind
to addclassName
support.
Usage
Basic Example
With react-navigation
Dynamic Class Names
Combining Multiple Style Objects
API Reference
Arguments
A string containing Tailwind class names to be resolved at runtime. Supports all standard Tailwind utilities and theme-based variants (e.g.,
dark:bg-gray-900
).Return Value
A valid React Native
style
object containing the resolved styles. This object can be passed directly to any component’s style
prop or combined with other style objects.Performance Considerations
The
useResolveClassNames
hook is reactive and will automatically update when the theme changes, ensuring your styles stay in sync with the active theme.useResolveClassNames
is optimized for performance, be aware that:
- It processes class names at runtime, which is slightly less performant than compile-time resolution
- For frequently re-rendered components, consider memoizing the result if the class names don’t change
- Using the
className
prop directly is more performant when possible