Invoke getTime() on the Date value and not on the date signal (#1284)
This commit is contained in:
@@ -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>;
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user