Answer the question
In order to leave comments, you need to log in
How to use componentWillUnmount to pop up a confirmation box?
For some elements, I want to make a confirmation popup when the user wants to leave it.
componentWillUnmount is perfect, but how do you undo and commit?
The idea is to display a modal with information and ask Yes / No there. If Yes, continue, if No, then cancel the transition. Tell me how.
Answer the question
In order to leave comments, you need to log in
No way. This method is created for cleanup in the component ( source ).
Use native browser methods for this.
// EDIT
If your component changes due to some event, it is logical that you need to warn the user in this handler, based on your conditions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question