reactjs - 无法从 useStyles material-ui 获取道具
问题描述
我正在尝试在 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 中使用我当前的索引而不是使用内联样式?
解决方案
像这样使用它:
const useStyles = props => makeStyles(theme => ({/* ... */ })();
or
const useStyles = props => {
// style construction
return makeStyles(style)();
};
推荐阅读
- javascript - 在 nodejs 中使用 import 通常使用 require
- javascript - 为什么我的构造函数状态属性没有发送到 server.js?
- swiftui - SwiftUI - Spotify Auth Webview 未在构建中加载但在预览中工作
- c++ - 无法将不同的结构值插入 Map
- java - 如何在 if 之间设置限制?
- javascript - 交互式 3d 动画注册和登录表格
- javascript - 为什么我的 Ionic App 在 Android 上收到强制“暗模式”?
- stm32 - STM32IDE 中的 CMSIS 问题
- shell - 后缀触发脚本
- c# - WPF DataGrid IsSelected 前景颜色动态变化