How to use setTimeout in react native?

358 Views Asked by At

Hi I working on a react native project I need to support my app offline. I used NetInfo Library from expo documentation.
like below

  const netInfo = useNetInfo();
const networkCheck = () => {
    setTimeout(() => {
      const net = netInfo.isInternetReachable;
      console.log(net);
      if (net === false) {
        setloadCachedListings(true);
      }
    }, 2000);
  };
  networkCheck();

I want to wait for some time at this step of my code because this hook always returns null first time then after few milliseconds it tells the real network status. But this code is not working as I an trying to do. Is there any way to achieve this? I just want to wait a little bit to get real network connection and then go further with my code.

logs for netInfo hook. enter image description here

0

There are 0 best solutions below