Search

Back

Copy Link

Library

/

Free

/

60

Countdown to Midnight Daily

60

Countdown to Midnight Daily

Not loading? Preview

Made by

@frameroverrides

override

none

Override

Countdown to Midnight Daily

Copy

Override

Copied to Clipboard!

Instructions

Apply to text layers.

Code Preview

import type { ComponentType } from "react"
import { useEffect, useState } from "react"

export function withCountdown(Component): ComponentType {
    return (props) => {
        const [timeRemaining, setTimeRemaining] = useState("")

        const calculateTimeRemaining = () => {
            const now = new Date()
            const tomorrow = new Date(now)
            tomorrow.setDate(tomorrow.getDate() + 1)
            tomorrow.setHours(0, 0, 0, 0)
            const difference = tomorrow.getTime() - now.getTime()

            const hours = Math.floor(
                (difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
            )
            const minutes = Math.floor(
                (difference % (1000 * 60 * 60)) / (1000 * 60)
            )
            const seconds = Math.floor((difference % (1000 * 60)) / 1000)

            return `${hours} hours ${minutes} mins ${seconds} secs`
        }

        useEffect(() => {
            const timer = setInterval(() => {
                setTimeRemaining(calculateTimeRemaining())
            }, 1000)

            // Clean up the interval when the component is unmounted
            return () => {
                clearInterval(timer)
            }
        }, [])

        return <Component {...props} text={timeRemaining} />
    }
}

Terms of Use for Free Assets

By accessing and using this Framer Override Library, you agree to the following terms:

All code snippets provided are available for your personal and professional use. This includes personal websites, client projects, and other website projects in Framer. You are strictly prohibited from sharing, redistributing, selling these code snippets, or creating derivative works for resale or distribution. Unauthorized sharing, distribution, or selling of these code snippets is a breach of these terms and may result in termination of your access to this library, along with potential legal action.