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!!
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!!