【发布时间】:2019-12-11 23:31:48
【问题描述】:
所以,每当我使用 withStyles 时,它都会创建一个名为 - (this.props.{classes}) 的默认道具,如果我使用 withTheme 它会创建 -(this.props.{主题})。
问题 1
这里的主题属性是包含与我正在使用的 MaterialUI 组件相关的主题数据,还是仅包含所有组件的主题数据?
问题 2
我的第二个问题是,如果我想将这些道具存储到单个对象中,例如 *this.props.header.classes and this.props.header.theme*。可以这样做吗?
问题 3
我的第三个问题是,类名是如何在内部定义的?据我说,他们可能正在使用像classnames 或clsx 这样的库。我说的对吗?
示例
这是为组件 appBar 创建的类名 - App-appBar-2
- 我认为是 appBar,因为那是样式对象中样式键的名称。
- 这里的数字
2有什么意义吗?
这里是样式的sn-p
const headerStyles = theme => ({
root: {
display: "flex"
},
appBar: {
zIndex: theme.zIndex.drawer + 1,
transition: theme.transitions.create(["width", "margin"], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen
})
},
...
...
)}
我有什么-
props = {
classes,
theme,
...
}
我打算拥有的是-
props = {
header: {
classNames: classes,
theme: theme
},
...
}
感谢任何帮助。
【问题讨论】:
标签: reactjs react-redux material-ui