如何解决事件函数的调用速度比 componentDidUpdate 快
我的 componentDidUpdate 正在更新类内部的状态。但是当我单击按钮时,首先调用 onClick 函数,因此它呈现旧状态。在我第二次单击按钮后,它会根据需要工作。请帮我解决第一次点击问题。
componentDidUpdate(prevProps: any,prevState: any) {
if (prevProps.is_related !== this.props.is_related) {
this.state.is_related = this.props.is_related
this.setState(this.state);
}
}
onDeleteCourse = (e: React.MouseEvent<HTMLButtonElement,MouseEvent>) => {
const deleteList = this.state.selected_ids;
this.props.dispatch(
Actions.ApiRequest(Constants.activity.ACTIVITY_IS_RELATED,deleteList,'activity-list-spin')
);
if (e && e.target && this.state.is_related) {
this.props.dispatch(
Actions.ShowModal({
//blablabla
})
);
} else if (e && e.target && !this.state.is_related) {
this.props.dispatch(
Actions.ShowModal({
//blablabla
})
);
}
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。