@arolariu/components
Version:
A collection of reusable components for React applications, built as ESM & CJS modules with tree shake, minify and bundler optimizations enabled, for the lowest bundle size (import cost)!
18 lines (17 loc) • 720 B
JavaScript
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
const MOBILE_BREAKPOINT = 768;
function useIsMobile() {
const [isMobile, setIsMobile] = __WEBPACK_EXTERNAL_MODULE_react__.useState(void 0);
__WEBPACK_EXTERNAL_MODULE_react__.useEffect(()=>{
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
const onChange = ()=>{
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
};
mql.addEventListener("change", onChange);
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
return ()=>mql.removeEventListener("change", onChange);
}, []);
return !!isMobile;
}
export { useIsMobile };
//# sourceMappingURL=use-mobile.js.map