我发现在类组件中声明状态有两种方式,如下所示:
class App extends Component {
constructor(props) {
super(props);
this.state = {
name: 'John'
}
}
render() {
return <div>{this.state.name}</div>
}
}
和
class App extends Component {
state = {
name: 'John'
}
render() {
return <div>{this.state.name}</div>
}
}
这两者之间有什么区别?