style()
Statically-shaped style fragments created with style()
style() creates statically shaped style fragments for the style prop and
piece-typed component props.
Module-scope definition
Call style() at module scope so its CSS rules are resolved and inserted once during module evaluation.
If style() is called during a component render, Tamagui emits a development warning:
For dynamic styles that depend on props, use styled.dynamic or a component .resolve callback instead.
The style prop
Tamagui’s style prop accepts a StylePiece, a plain style object, or an array containing both:
Array elements evaluate in order. Later pieces or style objects override earlier ones per property, following Tamagui’s standard style precedence.
Static shape rule
The object passed to style() must have statically known property keys:
Rules for style() definitions:
- Static property keys only.
- No object spreads into the definition literal.
- No computed keys.
- Structured leaf values (such as
shadowOffset) are allowed. - Flat clause strings (such as
'1 hover:0.8') are allowed.
Non-conforming pieces with dynamic spreads or computed keys deopt compiler extraction for that piece. The runtime remains unaffected and interprets the styles in JavaScript.
Native resolution
On web, style() compiles each property to atomic CSS classes at module evaluation.
On React Native and JavaScript drivers, the piece preserves its underlying style object. When rendered, Tamagui resolves the style object against the active theme and caches the resolved styles per (piece, theme) pair.
Piece-typed component props
Several Tamagui components accept a StylePiece on dedicated style props:
activeStyleonCheckbox,Toggle,ToggleGroup.Item, andTabs.Tab.contentContainerStyleonScrollView.
These props replace the legacy accept: 'style' configuration option. Components forward the piece directly into their frame’s style prop or resolve it against the active theme on native.