我有一个来自reactjs的代码,它正在工作,但是,我所说的woring是因为它做了它需要做的事情,在这种情况下,当按钮关闭时,它会展开并关闭。
我有一个来自控制台的错误
Failed prop type: Invalid prop `className` of type `object` supplied to `ForwardRef(IconButton)`, expected `string`.
in ForwardRef(IconButton) (created by WithStyles(ForwardRef(IconButton)))
虽然我的代码很简单,但我只想添加一些重要的ui扩展器
const { schedule, classes, onClick, deleteScd, visible } = props;
const [expanded, setExpanded] = React.useState(false);
const handleExpandClick = (e) => {
// setExpanded(!expanded);
e.preventDefault()
e.stopPropagation();
if(!expanded){
setExpanded(true);
}else{
setExpanded(false);
}
console.log(expanded)
};
<Draggable>
<Card className={classes.root} >
<CardActions disableSpacing className={classes.cardExpand } onClick={onClick} >
<Box className={classes.head} >
<Typography variant="h5" className={classes.title}>
{title}
</Typography>
<Typography className={classes.timezone} color="textSecondary">
{timezone}
</Typography>
</Box>
<IconButton
className={classes.expand, {
[classes.expandOpen]: expanded,
}}
onClick={handleExpandClick}
aria-expanded={expanded}
aria-label="show more"
>
<ExpandMoreIcon className={classes.expandIcon} />
</IconButton>
</CardActions>
<Collapse in={expanded} timeout="auto" unmountOnExit>
<Card className={classes.root} variant="outlined">
<CardContent style={{ padding: "10px 3px 3px 3px" }}>
Content
</CardContent>
</Card>
</Collapse>
</Card>
</Draggable>
我想解决这个问题,因为我的裁判有另一个问题。
发布于 2021-06-06 00:04:40
IconButton
组件的className
属性必须接收一个字符串值(正如属性类型警告所述)。只有当视图展开时,才可以使用三元表达式来应用类,例如className={expanded ? classes.expandOpen : ''}
。
https://stackoverflow.com/questions/67854315
复制