In react, will componentWillUnmount trigger when the browser is closed?

Will

componentWillUnmount trigger when the browser is closed? Alert is not triggered when the browser is closed.
the current project requirement is to save user data to localStorage when the user logs out and logs in. In which life cycle should it be written?
ask for advice

Apr.09,2021

will not, please use the beforeunload event.


It doesn't matter whether

will or not.

the important thing is that you shouldn't write in componentWillUnmount.

the reason is that the behavior of browser shutdown may not be executed in componentWillUnmount at all, and the request may not be sent in time.

so it can be controlled in onbeforeunload.


No, browsers are closed (tabs are closed) to listen for events such as onbeforeunload. Your requirement should be that you save data when dealing with logout logic


those who answer may not have personally tested, refresh the page will still trigger the onbeforeunload event, have you tried, or tried to avoid this problem.?.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b789-412d9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b789-412d9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?