gpt4 book ai didi

material-ui - material ui中的withStyle和withTheme有什么区别?

转载 作者:行者123 更新时间:2023-12-04 00:29:10 29 4
gpt4 key购买 nike

我是网络开发的新手,正在尝试使用 material-ui。我看到一些演示代码使用 withStyle,还有一些使用 withTheme。它们之间有什么区别吗?非常感谢!

最佳答案

我认为接受的答案没有得到很好的解释,要更清楚:

1) withStyles 在创建css样式时也提供了theme 对象;创建函数的签名如下:

const styles = theme => ({
root: {
maxWidth: 600,
},
tabs: {
borderTopWidth: 1,
borderTopStyle: 'solid',
borderColor: theme.palette.divider,
width: '100%',
},
});

正如人们所看到的那样,theme 以及其中的所有内容,如 theme.palette 都可以访问。官方文档和示例到处都是,所以我只是随机选择了this one . (按此按钮显示源代码:“< >”)

2) withTheme 的目的是将theme 注入(inject)到props 中,因此也可以在 等组件函数内部访问渲染,有时它很有用。官方文档 here .

关于material-ui - material ui中的withStyle和withTheme有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53799394/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com