[英]How to fix 'TypeError: Cannot read property 'style' of undefined' error when using material-ui Transitions
I'm trying to use transitions within my react app, but each time I try to use any transition module this error comes up: "TypeError: Cannot read property 'style' of undefined",我正在尝试在我的 React 应用程序中使用转换,但是每次我尝试使用任何转换模块时都会出现此错误:“TypeError:无法读取未定义的属性‘样式’”,
(anonymous function) node_modules/@material-ui/core/esm/Fade/Fade.js:83
(匿名函数) node_modules/@material-ui/core/esm/Fade/Fade.js:83
80 | style: _extends({
81 | opacity: 0,
82 | visibility: state === 'exited' && !inProp ? 'hidden' : undefined
> 83 | }, styles[state], style, children.props.style),
| ^ 84 | ref: handleRef
85 | }, childProps));
86 | });
I've tried not using es6 class style method, which actually fixes the problem, but I want to use es6 classes.我试过不使用 es6 类样式方法,这实际上解决了问题,但我想使用 es6 类。
I think it has something to do with the styles variable which I define at the top like so:我认为它与我在顶部定义的样式变量有关,如下所示:
const styles = theme => ({
typography: {
marginTop: theme.spacing(2)
}
});
class IndexPage extends Component {
constructor(props) {
super(props);
this.state = {
checked: false,
}
}
render() {
const {classes} = this.props;
return (
<React.Fragment>
<Typography className={classes.typography} align={"center"} variant={"h2"} component={"h2"}>
<Fade in={this.state.checked}>
Welcome to my Portfolio!
</Fade>
</Typography>
</React.Fragment>
)
}
}
IndexPage.propTypes = {
styles: PropTypes.object.isRequired,
};
export default withStyles(styles)(IndexPage);
I expect the text inside the typography tag to Fade in, but the App crashes.我希望排版标签内的文字淡入淡出,但应用程序崩溃了。
Fade the Typography
component:淡化
Typography
组件:
<React.Fragment>
<Fade in={this.state.checked}>
<Typography
className={classes.typography}
align={"center"}
variant={"h2"}
component={"h2"}
>
Welcome to my Portfolio!
</Typography>
</Fade>
</React.Fragment>;
For example:例如:
export default function App() {
return (
<FlexBox>
<Fade in={true}>
<Typography>Welcome</Typography>
</Fade>
</FlexBox>
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.