title: I'm having trouble in making a countdown timer (Reactjs )
body: <p>I'm using Reactjs to make a countdown timer that can separate to day, hours, minutes, and seconds between 2 dates. It works fine, but It can only count to a date that is larger than the current date (21/08/2022 &lt; 17/10/2022), but It cannot count to (21/08/2022 to 21/08/2023).
  I have a function to pass down props:</p>
  <pre><code>const timeLeft = useCountdown(new Date(2022, Data.date.month , Data.date.day));  
  </code></pre>
  <p>It should look like this when console.log:</p>
  <pre><code>{days: 87, hours: 20, minutes: 58, seconds: 40}
  </code></pre>
  <p>I'm using a useCountDown hook to count the time between 2 dates:</p>
  <pre><code>import { useState, useEffect } from &quot;react&quot;;
  
  const useCountdown = (deadline) =&gt; {
      const [days, setDays] = useState(0);
      const [hours, setHours] = useState(0);
      const [minutes, setMinutes] = useState(0);
      const [seconds, setSeconds] = useState(0);
    
      const leading0 = (num) =&gt; {
        return num &lt; 10 ? &quot;0&quot; + num : num;
      };
    
      const getTimeUntil = (deadline) =&gt; {
        const time = Date.parse(deadline) - Date.parse(new Date());
        if (time &lt; 0) {
          setDays(0);
          setHours(0);
          setMinutes(0);
          setSeconds(0);
        } else {
          setDays(Math.floor(time / (1000 * 60 * 60 * 24)));
          setHours(Math.floor((time / (1000 * 60 * 60)) % 24));
          setMinutes(Math.floor((time / 1000 / 60) % 60));
          setSeconds(Math.floor((time / 1000) % 60));
        }
      };
    
      useEffect(() =&gt; {
        setInterval(() =&gt; getTimeUntil(deadline), 1000);
    
        return () =&gt; getTimeUntil(deadline);
      }, [deadline]);
      
      return {
          days: leading0(days),
          hours: leading0(hours),
          minutes: leading0(minutes),
          seconds: leading0(seconds)
      };
  };
  
  export default useCountdown;
  </code></pre>
  <p>I haven't figured out how to fix this. Sorry for the bad English, but I'm trying my best :(
  Thank you for helping me!</p>