componentwillunmount和setState打开对话框以确认数据的保存
我目前有一个专门用于检查用户是否要保存其数据的组件Willunmount(如果尚未保存)。 我使用材料UI的对话框创建了一个自定义提示,该对话框是通过状态更改打开的。 在我简单地使用一个窗口之前。
componentWillUnmount = async () => {
if (this.documentChanged !== false) {
if (this.locationState.document_format_id === 2 || this.locationState.document_format_id === 1) {
this.promptActionTracker = "component_exit";
this.dialogTitle = "Exiting Component";
this.dialogText = "Do you wish to save document data?";
this.errorType = "information";
this.setState({dialogOpen: true});
}
}
};
我该如何打开提示,让用户单击“确定”或“取消”,处理该操作,然后卸载组件?
I currently have a componentWillUnmount used specifically to check if a user wants to save their data, if it has not been saved already.
I created a custom prompt using Material UI's dialog, which is opened via a state change.
Before I was simply using a window.confirm, but now that i want to use the custom prompt, I cannot, due to componentWillUnmount being a final render in the process.
componentWillUnmount = async () => {
if (this.documentChanged !== false) {
if (this.locationState.document_format_id === 2 || this.locationState.document_format_id === 1) {
this.promptActionTracker = "component_exit";
this.dialogTitle = "Exiting Component";
this.dialogText = "Do you wish to save document data?";
this.errorType = "information";
this.setState({dialogOpen: true});
}
}
};
How do I go about opening the prompt, letting the user click "Ok" or "Cancel", process that action, and only then unmount the component?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论