【发布时间】:2022-11-22 21:54:26
【问题描述】:
我在我的项目中使用 Mui v5 组件,目前我正在使用 sx 道具来设置所有 MUI 组件的样式,但是将 sx 放在每个组件的每一行中看起来不太好。所以,我想知道是否有任何其他方法可以像我们在 styled-components 库中那样为每个组件设置样式或应用自定义类。我也知道 MUI 的样式,但它用于制作可重用的组件,但我想使用一些可以帮助我准备可应用于任何组件的样式的东西。
下面是我的代码示例。
const theme = useTheme();
return (
<Box sx={{ border: '1px solid red', flex: 'auto', paddingLeft: '8px' }}>
<Box
sx={{
width: '100%',
height: '46px',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
background: theme.palette['P-10'],
padding: '8px 24px'
}}
>
</Box>
<Box sx={{ border: '1px solid green' }}>{AreaChartComp}</Box>
</Box>
);
};
If you see there i had to use sx 3 times, which do not want, instead am looking of other way where i can pass classes.
【问题讨论】:
-
你可以看看MUI styled
-
是的,我知道我正在使用它来制作可重用组件的样式。我想要 V5 中的 makeStyles 替代品,因为它在 v5 中显示为已弃用
标签: css reactjs material-ui styled-components mui5