import { useState, useEffect } from 'react'; | |
export function useIsMobile() { | |
const [isMobile, setIsMobile] = useState(true); | |
useEffect(() => { | |
const checkIfMobile = () => { | |
setIsMobile(window.innerWidth < 768); | |
}; | |
checkIfMobile(); | |
window.addEventListener('resize', checkIfMobile); | |
return () => window.removeEventListener('resize', checkIfMobile); | |
}, []); | |
return isMobile; | |
} | |