UNPKG

@sky-mavis/tanto-widget

Version:
13 lines 621 B
import {useState,useEffect}from'react';import {MOBILE_BREAKPOINT}from'../constants.mjs';import {isMobile}from'../utils/userAgent.mjs';function useIsMobileView() { const [mobile, setMobile] = useState(isMobile()); useEffect(() => { const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`); const onChange = () => { setMobile(window.innerWidth < MOBILE_BREAKPOINT); }; mql.addEventListener('change', onChange); setMobile(window.innerWidth < MOBILE_BREAKPOINT); return () => mql.removeEventListener('change', onChange); }, []); return !!mobile; }export{useIsMobileView};