【发布时间】:2021-05-28 01:32:08
【问题描述】:
我想控制切换到道具的背景颜色。但是 withStyles 的 props 是空的。
import Switch from '@material-ui/core/Switch';
import {withStyles, Theme, createStyles} from '@material-ui/core/styles';
import React from 'react';
import {PropsType} from "./propsType";
const AntSwitch = withStyles(({palette, props, ...other})=>{
console.log('withStyles', props) // here is empty
return ({
switchBase: {
'&$checked': {
'& + $track': {
opacity: 1,
backgroundColor: (props as PropsType.Switch).activeColor ?? palette.primary.main,
borderColor: palette.primary.main,
},
},
}
})
})(Switch);
export default function TPSwitch(props: PropsType.Switch) {
const {label, ...other} = props;
console.log('other', props)
return (
<AntSwitch {...other} />
)
};
在控制台中打印
other {label: "on", activeColor: "#E74060"}
TPSwitch.tsx:8 withStyles {}
【问题讨论】:
标签: reactjs typescript material-ui