我在listItem
之外定义的useStyles
中具有名为TodoListItem
的属性,如下所示:
const useStyles = makeStyles(theme => ({
listItem: {
textDecoration: 'none'
}
})
)
const TodoListItem({checked}) => {
const classes = useStyles();
return <ListItemText className={classes.listItem} primary={text}/>
};
然后我想基于名为textDecoration
的变量来更改checked
的状态。而且我尝试直接在checked
中使用useStyles
变量,但由于它超出范围而无法使用。
textDecoration: checked ? 'line-through' : 'none'
在这种情况下,如何将checked
变量传递给useStyles
以使三元运算符正常工作?
props
作为参数传递给样式钩子import { makeStyles } from "@material-ui/core/styles";
const useStyles = props =>
makeStyles(theme => ({
listItem: {
textDecoration: props.checked ? 'line-through' : 'none'
}
}));
const classes = useStyles(props)();