API reference
rx
API reference for the `rx` function
Overview
The rx()
function — short for React Expand — function allows you to inject dynamic inline variables into your React components.
It enables variable-based styling without breaking static CSS extraction.
✅ Works only in React JSX context. Not for plain DOM or non-React frameworks.
Purpose
React's inline style
attributes don't participate in class-based CSS extraction.
rx()
solves this by injecting CSS variables inline, while still using your static CSS classes.
Example
Apply multiple variables
You can apply as many CSS variables as you need:
You can also use expressions directly:
Extract logic
Return value
Returns an object with:
- className: your static class
- style: dynamic inline variable map
Use sparingly
There is a runtime cost to inline styles. Prefer static styles with css.create()
+ cx()
where possible.