0

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?

Vlad SD
  • 169
  • 1
  • 1
  • 11
  • would you also add the code related to your custom prompt – Shubham Sogi Jun 07 '22 at 05:13
  • it's a simple Material UI variant of Dialog with a few things to handle text generation. I don't think it's relevant, but MUI's Dialog documentation can be found at https://mui.com/material-ui/react-dialog/ – Vlad SD Jun 08 '22 at 06:34

0 Answers0