get
Theget function extracts values from deeply nested objects using dot notation paths. It’s used internally by Theme UI to resolve theme values and supports the special __default key for nested theme scales.
Function Signature
Parameters
object
required
The object to extract values from (typically a theme, variant, or style object).
string | number | undefined
required
Path to the desired value. Can be:
- Dot-separated string (e.g.,
'colors.primary.light') - Number for array access
undefinedreturns the fallback
any
Default value returned if the path is not found in the object. If not provided and path is not found, returns
undefined.number
Internal parameter for iteration (not intended for direct use).
unknown
Internal parameter for undefined checks (not intended for direct use).
Returns
any
The value at the specified path. If the value is an object with a
__default key, returns the value of that key. Returns the fallback value if the path doesn’t exist.How It Works
Basic Path Resolution
The function traverses the object using dot notation:The __default Key
When a path resolves to an object containing the special __default key, get returns the value of that key instead of the object itself:
Array Access
Arrays can be accessed using numeric indices:Fallback Values
When a path doesn’t exist, the fallback value is returned:The THEME_UI_DEFAULT_KEY
The __default key is exported as a constant:
Use Cases
Nested Color Scales
Create color palettes with multiple shades:Typography Scales
Safe Property Access
Useget to safely access potentially undefined paths:
Variant Extraction
Examples
Basic Usage
With Nested Scales
Dynamic Paths
In Custom Components
Internal Usage
Theget function is used internally by the css function for:
- Resolving theme values (e.g.,
color: 'primary'→color: theme.colors.primary) - Accessing scale values by index (e.g.,
padding: 3→padding: theme.space[3]) - Handling negative values for margins and positioning
- Processing variant references
