简体   繁体   English

使用 material-ui Transitions 时如何修复“TypeError:无法读取未定义的属性“样式”错误

[英]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>
  );
}

编辑 Q-56890709-FadeMaterial

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Material-UI样式ThemeProvider错误:TypeError:无法读取未定义的属性“ primary” - Material-UI styles ThemeProvider Error: TypeError: Cannot read property 'primary' of undefined 什么是 Uncaught TypeError:无法读取 AppBar + Drawer 组件(ReactJS + Material-UI)未定义的属性“打开”? - What is Uncaught TypeError: Cannot read property 'open' of undefined for AppBar + Drawer component (ReactJS + Material-UI)? React Material-UI Modal TypeError:无法读取未定义的属性“hasOwnProperty” - React Material-UI Modal TypeError: Cannot read property 'hasOwnProperty' of undefined ReactJS-&gt; Material-UI未捕获的TypeError:无法读取未定义的属性“ toUpperCase” - ReactJS -> Material-UI Uncaught TypeError: Cannot read property 'toUpperCase' of undefined Material-UI:DataGrid 组件错误:无法读取未定义的属性“长度” - Material-UI: DataGrid Component Error: Cannot read property 'length' of undefined 无法读取未定义的“组件”:在浏览器中使用 material-ui - Cannot read 'component' of undefined: Using material-ui with browserify 类型错误:无法读取未定义错误的属性“样式” - TypeError: Cannot read property 'style' of undefined error 未捕获的TypeError:使用for循环时无法读取未定义的属性&#39;style&#39; - Uncaught TypeError: Cannot read property 'style' of undefined when using for loop 如何修复错误“错误类型错误:无法读取未定义的属性‘0’” - how to fix the error "ERROR TypeError: Cannot read property '0' of undefined" 如何修复错误类型错误:无法读取未定义的属性“地图” - How to fix the error TypeError: Cannot read property 'map' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM