我正在尝试通过useStyles挂钩传递当前索引,以根据此索引显示组件,如下所示:
const useStyles = makeStyles(theme => {
console.log(theme);
return {
root: {
flexGrow: 1,
display: theme.props.currentIndex !== 0 ? 'none' : void 0
}
};
});
我看到我们可以将道具传递给useStyle钩子,所以我传递了我的当前值以在makeStyles中使用它:
const AcademicDegresPanel = props => {
const classes = useStyles(props);
console.log(props.currentIndex)
return (
<Grid container className={classes.root}>
Degrés academique
</Grid>
);
};
但是当我记录主题时,它在props键中没有currentIndex:
palette: {common: {…}, type: "light", primary: {…}, secondary: {…}, error: {…}, …}
props:
__proto__: Object
如何在makeStyles中使用当前索引而不是使用内联样式?
答案 0 :(得分:2)
像这样使用它:
const useStyles = props => makeStyles(theme => ({/* ... */ })();
or
const useStyles = props => {
// style construction
return makeStyles(style)();
};