Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.

//101-Example
const callback = useCallback((event: any) => {
      event.data.status === "complete" ? setProgress(0) : setProgress(event.data.uploadProgress);
    },[])
  
  useEffect(() => {
    window.addEventListener("file-upload", callback);
    return () => window.removeEventListener("file-upload", callback);
  }, [window, callback]);
Source by codedaily.io #
 
PREVIOUS NEXT
Tagged: #To #cancel #subscriptions #asynchronous #tasks #useEffect #cleanup
ADD COMMENT
Topic
Name
7+4 =