lightswind
Version:
A collection of beautifully crafted React Components, Blocks & Templates for Modern Developers. Create stunning web applications effortlessly by using our 160+ professional and animated react components.
18 lines (17 loc) • 647 B
JavaScript
// @ts-nocheck
import * as React from "react";
const MOBILE_BREAKPOINT = 1024;
export function useIsMobile() {
const [isMobile, setIsMobile] = React.useState(typeof window !== 'undefined' ? window.innerWidth < MOBILE_BREAKPOINT : false);
React.useEffect(() => {
if (typeof window === 'undefined')
return;
const checkMobile = () => {
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
};
window.addEventListener('resize', checkMobile);
checkMobile(); // Initial check
return () => window.removeEventListener('resize', checkMobile);
}, []);
return isMobile;
}