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.
When to Use This Hook
UseuseResolveClassNames when you need to:
- Configure libraries that accept style objects (e.g.,
react-navigationthemes) - Pass styles to third-party components that only accept
styleprops (and can’t be wrapped inwithUniwind) - Generate style objects dynamically for special use cases
- Work with legacy code that requires style objects
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
classNameprop directly is more performant when possible