diff --git a/docs/getting-started/adding-interactivity.md b/docs/getting-started/adding-interactivity.md index 767ec13e..b840c0ca 100644 --- a/docs/getting-started/adding-interactivity.md +++ b/docs/getting-started/adding-interactivity.md @@ -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 🎉; } // Otherwise, we format the remaining time using `Intl.RelativeTimeFormat` and // render it. - const secondsLeft = Math.floor((target.getTime() - now.getTime()) / 1000); return {timeFmt.format(secondsLeft, "seconds")}; } ```