这是代码。不知道为什么会出现问题。
class TeacherForm extends Component {
constructor({ data }) {
super();
this.isUpdatingForm = !! data;
this.state = Object.assign({ ... });
this.handleSubmit = this.handleSubmit.bind(this);
this.removeTeacher = this.removeTeacher.bind(this);
}
handleChange(value, field) {
this.setState({ shouldUpdate: true, [field]: value });
}
handleSubmit(e) {
e.preventDefault();
const { name, subjects, parttime, timing } = this.state;
if (this.isUpdatingForm) {
return update.call({
_id: this.props.data._id,
transaction: { name, subjects, parttime, timing },
}, () => this.setState({ shouldUpdate: false }));
}
return add.call();
}
removeTeacher() {
return remove.call(this.props.data._id);
}
render() {
return (
<form onSubmit={this.handleSubmit}>
...
</form>
);
}
}
在update.call
的回调中,handleSubmit方法会抛出错误。这通常会在我调用removeTeacher
并且列表更新并且此组件卸载时显示。
答案 0 :(得分:0)
听起来好像是在卸载组件之后执行回调 def randomAlphaNumericChar(): Char = {
val ALPHA_NUMERIC_STRING = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789".toCharArray
Gen.oneOf(ALPHA_NUMERIC_STRING)
}
。那可能吗?如果是这样,解决这个问题的一种方法是用
() => this.setState({ shouldUpdate: false })
并添加
return update.call({
_id: this.props.data._id,
transaction: { name, subjects, parttime, timing },
}, () => { !this.unmounted && this.setState({ shouldUpdate: false }); });