Invoke getTime() on the Date value and not on the date signal (#1284)

This commit is contained in:
Naju Mancheril
2023-06-15 15:01:08 +00:00
committed by GitHub
parent 673ed2d90f
commit a1d266f0d3
+5 -2
View File
@@ -54,14 +54,17 @@ export default function Countdown(props: { target: string }) {
return () => clearInterval(timer);
}, [props.target]);
const secondsLeft = Math.floor(
(target.getTime() - now.value.getTime()) / 1000,
);
// If the target date has passed, we stop counting down.
if (now > target) {
if (secondsLeft <= 0) {
return <span>🎉</span>;
}
// Otherwise, we format the remaining time using `Intl.RelativeTimeFormat` and
// render it.
const secondsLeft = Math.floor((target.getTime() - now.getTime()) / 1000);
return <span>{timeFmt.format(secondsLeft, "seconds")}</span>;
}
```