import { useEffect, useState } from 'react' import DarkModeButton from './DarkModeButton' let windowTop = 0 export default function FloatDarkModeButton () { const [show, switchShow] = useState(false) const scrollListener = () => { const scrollY = window.pageYOffset const shouldShow = scrollY > 100 && scrollY < windowTop windowTop = scrollY if (shouldShow !== show) { switchShow(shouldShow) } } useEffect(() => { document.addEventListener('scroll', scrollListener) return () => document.removeEventListener('scroll', scrollListener) }) return (