Prerequisites
better-styled usesclassName for styling. You need a Tailwind-to-StyleSheet solution:
- NativeWind - Tailwind CSS utilities for React Native
- Uniwind - High-performance Tailwind bindings for React Native (by the Unistyles team)
Both libraries convert Tailwind class names to React Native styles. Follow their installation guides first - better-styled works with both out of the box.
Basic Usage
Pressable States
Use Tailwind’s state modifiers directly in your className:style={({ pressed }) => ...} - the className handles it cleanly.
Platform-Specific Styles
Useios: and android: prefixes directly in className:
Function Composition: Haptics Example
One of better-styled’s most powerful features is function composition. Event handlers from different sources (base, variants, direct props) all execute in sequence - they don’t overwrite each other. This is perfect for things like haptic feedback:- ① Base
onPress(if any) - ② Variant
onPress(haptics feedback) - ③ Direct
onPressprop (your handler)
- 📳 Haptics - Tactile feedback as part of component UX
- 🔊 Sound effects - Audio feedback on interactions
Full Example: Button Component
A complete button component with context and slots:Tips
Use Pressable, not TouchableOpacity
Use Pressable, not TouchableOpacity
Pressable is the modern way to handle touches in React Native. It’s more flexible and has better TypeScript support.Leverage className state modifiers
Leverage className state modifiers
NativeWind and Uniwind support
active:, focus:, disabled: and other state modifiers. Use them instead of managing state manually.Function composition is your friend
Function composition is your friend
Add haptics or sound effects at the variant level. They won’t interfere with handlers passed directly to the component.
Don't shadow native props
Don't shadow native props
Avoid naming variants after existing component props. For example, use
isDisabled instead of disabled since Pressable already has a disabled prop. This prevents confusion and type conflicts.style prop overrides className
style prop overrides className
The
style prop has higher priority than className. If you pass style={{ backgroundColor: 'red' }}, it will override any background color set via Tailwind classes.Next: TypeScript Guide
Get the most out of type inference