Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Remove the warning for setState on unmounted components in React

useEffect(() => {
  let isMounted = true;               // note mutable flag
  someAsyncOperation().then(data => {
    if (isMounted) setState(data);    // add conditional check
  })
  return () => { isMounted = false }; // cleanup toggles value, if unmounted
}, []);                               // adjust dependencies to your needs
Comment

Remove the warning for setState on unmounted components in React

function useAsync(asyncFn, onSuccess) {
  useEffect(() => {
    let isActive = true;
    asyncFn().then(data => {
      if (isActive) onSuccess(data);
    });
    return () => { isActive = false };
  }, [asyncFn, onSuccess]);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: likedislike 
Javascript :: solana solana-Web3.js change for devnet lamports to production transaction 
Javascript :: path error 
Javascript :: get moment from another moment 
Javascript :: geojson polygon mongoose 
Javascript :: how to remove elevation tab bar react native 
Javascript :: es6 parameter destructuring nested object 
Javascript :: how to square a number in html 
Javascript :: error-too-many-re-renders-react-limits-the-number-of-renders-to-prevent 
Javascript :: convert milliseconds to hours minutes seconds javascript 
Javascript :: javascript perms 
Javascript :: launch chrome in incognito and dev tools 
Javascript :: babel plugins nuxt 
Javascript :: Script test to be oneOf 
Javascript :: how to change the backgroung of one button when click the other one 
Javascript :: dummy servers using nodejs 
Javascript :: puppeeter pdf desktop 
Javascript :: @Scheduled cron expresssion 
Javascript :: Array-multiple test case 
Javascript :: duplicate serial numbers asset 
Javascript :: a7aad 
Javascript :: javascript find the smallest and biggest number in array 
Javascript :: python faker json 
Javascript :: javascript pure ajax promise 
Javascript :: Set object Relation with Array objects javascript 
Javascript :: loopback 4 pagination 
Javascript :: child to perent data transfer in angular 
Javascript :: role based authentication in node js mongodb 
Javascript :: regular expression for beginners 
Javascript :: array string to length number 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =