Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
477 B
2
Indexable
Never
useEffect(() => {
  const handleBeforeUnload = (e) => {
    if (isUploading) {
      const message = 'An upload is in progress. Are you sure you want to leave?';
      e.returnValue = message; // For most browsers
      return message; // For some older browsers
    }
  };

  if (isUploading) {
    window.addEventListener('beforeunload', handleBeforeUnload);
  }

  return () => window.removeEventListener('beforeunload', handleBeforeUnload);
}, [isUploading]);
Leave a Comment