我知道他们是类似的问题,但是我仍然对以下内容感到困惑。
何时使用这样的状态
Class Example extends Component {
state = {
name: ''
}
}
过度构造器道具
Class Example extends Component{
constructor(props) {
super(props);
this.state = {
name: ''
}
}
}
它与方法绑定有关吗?因为我可以很好地使用onChange而不用像这样绑定它:
this.onChange = this.onChange.bind(this)
我仍然可以像这样调用onChange
onChange = (e) => {
}
<Component onChange = {this.onChange} />
蛊毒传说
翻阅古今
相关分类