简体   繁体   English

React.js语法问题

[英]Problems with syntax of React.js

please help me in the code. 请帮助我的代码。 i have a problem with getInitialState() , the code isn't work: enter image description here 我对getInitialState()有问题,代码不起作用: 在此处输入图片描述

the mistake is on the picture, but i can't see this. 错误在图片上,但是我看不到。

You're using ES6 classes, which means you need to use a constructor to initialize the state: 您正在使用ES6类,这意味着您需要使用构造函数来初始化状态:

class App extends Component {
    constructor(props) {
        super(props);
        this.state = {
            show: true
        };
    }

    // ..
}

Reference: What is the difference between using constructor vs getInitialState in React / React Native? 参考: 在React / React Native中使用构造函数与getInitialState有什么区别?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM