0

I want to implement a method in react native which is execute in every 1 min and check the time is completed on not. for example i want to show a popup when 12:00 pm is completed. i just create a set interval method which is execute is every 1 min and check 12:00 complete or not. so please suggest the solution.

vjtechno
  • 452
  • 1
  • 6
  • 16
  • Why not using `setInterval`? – Itay Ganor Sep 03 '21 at 11:03
  • @ItayGanor i a using it but i unable to do that.please suggest solution if you can solve it – vjtechno Sep 03 '21 at 11:06
  • 1
    Does this answer your question? [How to setInterval for every 5 second render with React hook useEffect in React Native app?](https://stackoverflow.com/questions/57542264/how-to-setinterval-for-every-5-second-render-with-react-hook-useeffect-in-react) – iunfixit Sep 03 '21 at 11:21

1 Answers1

0

Try this:

import React, { useEffect } from 'react';
const dateToCheck = new Date();
const App = () => {
  const [hasTimePassed, setHasTimePassed] = useState(false);
  useEffect(() => {
    const intervalId = setInterval(() => {
      if (new Date() > dateToCheck) {
        setHasTimePassed(true);
      }
    }, 60000)
    return () => {
      clearInterval(intervalId);
    }
  }, []);
};
Asen Mitrev
  • 633
  • 3
  • 10