Skip to main content

stylex.props

Takes an StyleX style or array of StyleX styles, and returns a props object. Values can also be null, undefined, or false.

The return value should be onto an element to apply the styles directly.

For Solid, Svelte, Qwik, Vue, & others: stylex.attrs

For frameworks that expect class instead of className, use style.attrs instead. The usage is otherwise identical to stylex.props.

function props(styles: StyleXStyles | StyleXStyles[]): {
className: string;
style: {[key: string]: string};
};

Example use:

import * as stylex from '@stylexjs/stylex';

const styles = stylex.create({
root: {
backgroundColor: 'red',
padding: '1rem',
paddingInlineStart: '2rem',
},
conditional: {
backgroundColor: 'blue',
},
dynamic: (opacity) => ({
opacity,
}),
});

<div
{...stylex.props(
styles.root,
condition && styles.conditional,
props.style,
styles.dynamic(state.opacity),
)}
/>;