sweetalert-react icon indicating copy to clipboard operation
sweetalert-react copied to clipboard

Dismount when changing url

Open vtni opened this issue 6 years ago • 3 comments

When changing the url (clicking browsers back button), the component is unmounted, but still visible. Is it possible to hide then also the SweetAlert dialog? I tried it with forceUpdate(), but the rendering method is not called anymore after componentWillUnmount().

Thank you

vtni avatar Jul 17 '19 16:07 vtni

I fixed this using the event triggered by the back button to update the alert state

componentDidUpdate(){ window.onpopstate = (e) => { this.setState({ alert:false }) } }

ViniciusGularte avatar Aug 01 '19 13:08 ViniciusGularte

In Chrome 77 "window.onpopstate" working only after user interaction.

I fixed this using the event triggered by the back button to update the alert state

componentDidUpdate(){ window.onpopstate = (e) => { this.setState({ alert:false }) } }

rubinchyk avatar Oct 07 '19 20:10 rubinchyk

I fixed this using the event triggered by the back button to update the alert state

componentDidUpdate(){ window.onpopstate = (e) => { this.setState({ alert:false }) } }

Unfortunately, I get the same error:

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

vtni avatar Oct 19 '19 11:10 vtni