【发布时间】:2020-07-12 00:43:04
【问题描述】:
我正在尝试在 useStyles 挂钩中传递我当前的索引,以根据这个索引显示我的组件,如下所示:
const useStyles = makeStyles(theme => {
console.log(theme);
return {
root: {
flexGrow: 1,
display: theme.props.currentIndex !== 0 ? 'none' : void 0
}
};
});
我看到我们可以将 props 传递给 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 中使用我当前的索引而不是使用内联样式?
【问题讨论】:
-
为此的许多代码,我只是需要根据索引显示选项卡,我收到了答案,但感谢您的建议:)
标签: reactjs material-ui react-hooks