Overview
Thevars utility was used to create and manage CSS variables in React Native applications. It has been deprecated in favor of more stable and performant alternatives.
Migration
There are two recommended migration paths:Option 1: Use useUnstableNativeVariable (Recommended)
Option 2: Use Tailwind CSS Variables Directly
Define variables in your CSS and reference them in your classes:global.css
API Reference (Deprecated)
Import
The
vars utility is re-exported from react-native-css and has been marked as deprecated in NativeWind v5.Type Signature
Parameters
An object containing CSS variable names and their values.
- Keys should be valid CSS variable names (without the
--prefix) - Values can be strings or numbers
- String values are used as-is
- Number values are converted to appropriate units
Returns
A style object that can be passed to the
style prop of React Native components.This object contains the CSS variables in a format compatible with React Native’s styling system.Examples
Why Was It Deprecated?
Thevars utility was deprecated for several reasons:
- Performance: CSS variables defined in Tailwind’s theme configuration are processed at build time, resulting in better runtime performance
- Type Safety: Theme variables in Tailwind config provide better TypeScript integration and autocomplete support
- Consistency: Using Tailwind’s theme system maintains consistency across your entire application
-
Maintenance: The
react-native-csspackage provides more stable alternatives likeuseUnstableNativeVariablefor runtime variable management
Best Practices
For static values, always prefer Tailwind theme configuration over runtime CSS variables.
When to Use Runtime Variables
Only use runtime CSS variables (viauseUnstableNativeVariable) when:
- Values change based on user interaction
- Values are computed dynamically from props or state
- You need to animate between different variable values
When to Use Theme Configuration
Use Tailwind theme configuration for:- Brand colors and design tokens
- Spacing scales and typography
- Any values that don’t change at runtime
- Values shared across multiple components