Skip to content

Use recipes and state variants

export const button = styleVariants({
default: { opacity: 1 },
pressed: { opacity: 0.8 },
})

This is a good fit when the state model is small and you only need named branches.

Use recipe for reusable component surfaces

Section titled “Use recipe for reusable component surfaces”

Use recipe when you need:

  • defaults
  • multiple variant groups
  • compound variants
  • one reusable component-facing surface
const styles = useThemedStyles(s)
const resolveButtonStyle = useMemo(
() => createRecipeResolver(styles.button, { cacheSize: 32 }),
[styles.button],
)

Then select state explicitly:

<Pressable style={({ pressed }) => resolveButtonStyle({ pressed, tone: "primary" })} />

The resolver precomputes variant order, defaults and compound matchers. Its selection cache is bounded to the resolver lifetime; cacheSize: 0 disables retention. Use resolveButtonStyle.getCacheStats() for hit/miss/eviction receipts and call resolveButtonStyle.dispose() when an owned resolver is no longer needed.

React Native has no CSS selector engine. There is no native equivalent of &:hover, &:focus, or &:active in .css.ts. State must come from component props or runtime callbacks.