stylex.create
Takes a map of style objects and returns an object of compiled StyleX styles. The compiled StyleX styles are a mapping of keys to class names.
function create<T extends {[key: string]: RawStyles | (...any[]) => RawStyles}>(
styles: T,
): {[Key in keyof T]: StyleXStyles<T[Key]>};
Example use:
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
root: {
backgroundColor: 'red',
padding: '1rem',
paddingInlineStart: '2rem',
},
dynamic: (r, g, b) => ({
color: `rgb(${r}, ${g}, ${b})`,
}),
});
Requires Typescript 5+
Since stylex.create
uses the new const
keyword in its type definition, it requires Typescript 5+.
See references: