Skip to main content

Signature

Parameters

object
required
An object defining the variant names and their possible values.Each key is a variant name. Each value is an array of possible values.

Special Values

array
Use ["boolean"] for true/false variants. This produces a proper boolean type instead of "true" | "false".

Returns

object
An object with:
React.Context
The underlying React context. Rarely needed directly.
React.Provider
The context provider component. Used internally by styled components.
function
Hook to read current variant values. Returns null outside a provider.
T
The original variants object. Used for type inference.

Examples

Basic

With styled()

Multiple Variants

Using useVariants

Type Inference

Types are automatically inferred from the arrays:
No as const needed.

Notes

Context values are provided when a parent component with context receives variant props or has defaultVariants defined. Children automatically inherit these values.
Only variants defined here will propagate to children. You can define additional local variants in styled() that stay on a single component. See Local Variants.
Always define arrays inline in createStyledContext(). Assigning them to variables first can break type inference.

See Also