Search code examples
reactjsonbeforeunloadunmount

Why closing a page does not unmount the component


I know there is normally unmounting the child in a parent and it's not okay to unmount a child itself. But I am just curious about it that why the unloading (closing the page) will not trigger the unmount event. Something interesting behind this design? I looked around but found nothing till now.

Thank you for any idea provided here!

Best wishes, Hearen.


Solution

  • Closing the page will actually discard the main process/thread which handles the rendering of the web page. In that case, there is actually no way of calling the unmounting method since the thread which calls that method is discarded.