0

I am new to this using moment js, I took this sample from the internet and modified it according to my way, Here I want the countdown to start from 2 min: 00 sec to 00:00.

import React, { useEffect, useState } from "react";
import moment from "moment";

export default function CountdownMonths(){
  const [currentTime, setCurrentTime] = useState(moment());
  const timeBetween = moment.duration({
    "minutes": 2,
    "seconds":"00"
  });



  useEffect(() => {
    const interval = setInterval(() => {
      setCurrentTime(moment());
    }, 1000);

    return () => clearInterval(interval);
  }, []);

  return (
    <>
      <p>Deadline comes in</p>
      <p className="counter">
        <span>{timeBetween.minutes()}m: </span>
        <span>{timeBetween.seconds()}s </span>
      </p>
    </>
  );
};

How shall I start the countdown on page render? Any help would be much appreciated.

Dante1021
  • 304
  • 7
  • 20
  • Does this answer your question? [Countdown timer using Moment js](https://stackoverflow.com/questions/16129157/countdown-timer-using-moment-js) – Weedoze Jun 02 '22 at 07:19
  • Actually I am not getting this, is there any other solution for this? – Dante1021 Jun 02 '22 at 07:48

0 Answers0