schiehll / react-alert

alerts for React
MIT License
607 stars 99 forks source link

Calls setState after parent component unmounts #54

Closed AkyunaAkish closed 6 years ago

AkyunaAkish commented 6 years ago

I have 4 pages, each with the AlertContainer.

If I start an alert on one page, then switch to another page before the alert completes, the timeout of the previous page's alert container will still run and try to call setState, causing an error/warning:

"Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.". 

It would be nice to have a method available on the AlertContainer to clear it's timeout prematurely so that on my parent component's componentWillUnmount lifecycle method I can stop the timeout from continuing to run.

Thanks

schiehll commented 6 years ago

Should be fixed with v3, feel free to reopen it if v3 doesn't fix it for you.