【发布时间】:2017-07-07 14:49:16
【问题描述】:
请帮助我编写代码。 我对 getInitialState() 有疑问,代码不起作用: enter image description here
错误在图片上,但我看不到。
【问题讨论】:
-
永远不要将代码作为图片发布。
-
非常感谢,现在可以使用了
标签: javascript reactjs
请帮助我编写代码。 我对 getInitialState() 有疑问,代码不起作用: enter image description here
错误在图片上,但我看不到。
【问题讨论】:
标签: javascript reactjs
您使用的是 ES6 类,这意味着您需要使用构造函数来初始化状态:
class App extends Component {
constructor(props) {
super(props);
this.state = {
show: true
};
}
// ..
}
参考:What is the difference between using constructor vs getInitialState in React / React Native?
【讨论】:
this 等。