// index.jsReactDOM.render(<React.StrictMode><SnackbarProviderpreventDuplicatemaxSnack={3}><App/></SnackbarProvider></React.StrictMode>,document.getElementById("root"));// App.js// https://github.com/jacobbuck/react-beforeunload/blob/master/src/useBeforeunload.jsconst[message,setmessage]=useState("");const{ enqueueSnackbar, closeSnackbar }=useSnackbar();lethandled;useEffect(()=>{consthandleBeforeunload=(event)=>{if(handled)return;constsaveTask=async(key)=>{functionasync_sleep(ms){returnnewPromise((resolve)=>setTimeout(resolve,ms));}awaitasync_sleep(500);handled=true;closeSnackbar(key);window.close();};// save toast:// https://iamhosseindhv.com/notistack/demos#customizing-snackbars-individuallyconstaction=(key)=>(<><br/><ButtononClick={()=>saveTask(key)}>Save</Button><ButtononClick={()=>closeSnackbar(key)}>Cancel</Button></>);constwarn_msg="You have to save recording before exit!";enqueueSnackbar(warn_msg,{variant: "info",anchorOrigin: {vertical: "bottom",horizontal: "right",},persist: true,action: action,});// show warn popup.// Chrome requires `returnValue` to be set.// Some browsers like chrome display a fixed message.event.returnValue=warn_msg;returnevent.returnValue;};window.addEventListener("beforeunload",handleBeforeunload);return()=>{window.removeEventListener("beforeunload",handleBeforeunload);};},[]);// eslint-disable-line react-hooks/exhaustive-deps