Skip to main content

Syntax

RecastStyles
required
Configuration object defining the styles, variants, modifiers, and defaults
Returns: RecastStylesObject - A style object that can be applied to components or used to extract class names

Configuration Properties

string | string[] | object
Foundation classes applied to all instances.
object
Mutually exclusive styling options.
object
Boolean flags that can be combined.
object
Default values to reduce prop repetition.
array
Apply styles only when specific conditions are met.

Return Value

The style object provides two main capabilities:

Component Application

Apply styles to any React component:

Style Extraction

Extract computed class names for advanced use cases:

TypeScript Integration

Recast automatically generates TypeScript types:

Performance

Automatic Memoization

All style computations are cached for fast repeated access

LRU Cache

Prevents memory leaks with configurable cache size limits
Performance Tip: Create style objects outside of components to avoid recreation on every render.

Best Practices

Semantic Naming

Use meaningful names like variant and size rather than generic names

Set Defaults

Define sensible defaults to reduce prop repetition

Single Responsibility

Keep each style object focused on one concern

Compose Ready

Design styles to work well with recast.compose()