Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (23 sloc) 590 Bytes
import { useEffect, useState } from 'react';
export default function useIsMobile() {
const [isMobile, setIsMobile] = useState(window.innerWidth <= 576);
useEffect(() => {
function handleResize() {
if (window.innerWidth <= 576) {
if (!isMobile) {
setIsMobile(true);
}
} else {
if (isMobile) {
setIsMobile(false);
}
}
}
window.addEventListener('resize', handleResize);
handleResize();
return () => {
window.removeEventListener('resize', handleResize);
};
});
return isMobile;
}
You can’t perform that action at this time.