itzpradip / react-navigation-v5-mix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

setTimeout is causing memory leaks.

bleedingAyush opened this issue · comments

The setTimeout function which you are using in App.js is causing memory leaks. To fix this you can clear the timeout

useEffect(() => {
    const timeout = setTimeout(async() => {
    
      let userToken;
      userToken = null;
      try {
        userToken = await AsyncStorage.getItem('userToken');
      } catch(e) {
        console.log(e);
      }
      dispatch({ type: 'RETRIEVE_TOKEN', token: userToken });
    }, 1000);
   return = () => {
      timeout() 
   }
  }, []);