跳到主內容

stylex.create

取得一個包含 style 物件的對應,並傳回已編譯 StyleX style 的物件。已編譯 StyleX style 是一種將鍵值對應到類別名稱的對應。

function create<T extends {[key: string]: RawStyles | (...any[]) => RawStyles}>(
styles: T,
): {[Key in keyof T]: StyleXStyles<T[Key]>};

範例使用:

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})`,
}),
});