File size: 413 Bytes
d59a538 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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;
}
|