【发布时间】:2020-11-11 18:47:14
【问题描述】:
我想知道是否有一种方法可以访问 MyComponent 中的 theme.customElements.acitonButton 而无需使用 makeStyles?例如,我可以输入 className={theme.customElements.actionButton} 吗?
theme.js
const theme = createMuiTheme({
customElements: {
actionButton: {
backgroundColor: '#007AFF'
}
}
})
export default theme
MyComponent.tsx
import { makeStyles, createStyles, Theme } from '@material-ui/core'
// wondering if i can remove makeStyles and somehow access styles set in theme.js and add to <IconButton />?
const useStyles: any = makeStyles((theme: Theme) => {
return createStyles({
actionButton: theme.customElements.actionButton
})
})
const MyComponent: React.FunctionComponent<MyComponentProps> = props => {
const classes = useStyles()
<IconButton className={classes.actionButton} />
}
【问题讨论】:
标签: javascript material-ui themes formik-material-ui