Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
481 B
1
Indexable
Never
useEffect(() => {
  const handleBeforeUnload = (e) => {
    console.log('Attempting to navigate away during upload'); // Debugging line
    if (isUploading) {
      const message = 'An upload is in progress. Are you sure you want to leave?';
      e.returnValue = message;
      return message;
    }
  };

  window.addEventListener('beforeunload', handleBeforeUnload);

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