【发布时间】:2018-06-17 02:36:07
【问题描述】:
在将其标记为 React this.setState is not a function 的副本之前,我已经看到并阅读了它。
我的问题是,即使我已经绑定了处理程序,我也会收到此错误消息。
class EditAccount extends Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
}
state = {
showForm: false
}
componentWillMount() {
this.setState = {
showForm: false
}
}
render() {
return (
<div>
<button onClick={this.onClick}>Edit</button>
{this.state.showForm ? ( <Stuff/> ): null }
</div>
)
}
//toggle form visibility
onClick(e) {
const showing = this.state.showForm;
if (showing) {
this.setState({ showForm: false });
} else {
this.setState({ showForm: true });
}
}
}
有什么想法吗?
【问题讨论】:
标签: reactjs