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.