Skip to content

Auto switch to dark mode at sunset time 🌙 #541

Description

@anoopcodehack

Auto switch to dark mode at sunset time 🌙

File: client/src/pages/Dashboard.jsx

Dark mode is always on 💀
Should auto switch based on time of day fr!!

Fix:
const isNightTime = () => {
const hour = new Date().getHours()
return hour >= 18 || hour < 6
}

const [isNight, setIsNight] = useState(isNightTime())

useEffect(() => {
const interval = setInterval(() => {
setIsNight(isNightTime())
}, 60000) // check every minute
return () => clearInterval(interval)
}, [])

// show indicator in navbar:
{isNight ? (
🌙 Night mode
) : (
☀️ Day mode
)}

~12 lines! No backend needed 🎯
Connect to theme context for full effect!!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions