Skip to content

Commit

Permalink
Another fix of countdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Akim Mamedov committed Mar 14, 2024
1 parent 4b12dd0 commit a279b01
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions web/src/hooks/useCountdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ const format = ({ months = 0, days = 0, hours = 0, minutes = 0, seconds = 0 }) =
`${months}M ${days}d ${hours}h ${minutes}m ${seconds}s`;

export const useCountdown = (date) => {
const [duration, setDuration] = useState(
isPast(date) ? {} : intervalToDuration({
const [duration, setDuration] = useState({});

useEffect(() => {
setDuration(isPast(date) ? {} : intervalToDuration({
start: Date.now(),
end: date,
}),
);
}));

useEffect(() => {
const timer = setInterval(() => {
if (isPast(date)) {
clearInterval(timer);
setDuration({});
return;
}

const intToDur = intervalToDuration({
setDuration(intervalToDuration({
start: Date.now(),
end: date,
});
setDuration(intToDur);
}));
}, 1000);

return () => clearInterval(timer);
Expand Down

0 comments on commit a279b01

Please sign in to comment.