chentsulin / sweetalert-react

Declarative SweetAlert in React
http://chentsulin.github.io/sweetalert-react/
MIT License
239 stars 60 forks source link

Dismount when changing url #115

Open vtni opened 5 years ago

vtni commented 5 years ago

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

ViniciusGularte commented 5 years ago

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 commented 5 years ago

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 }) } }

vtni commented 5 years ago

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.