import React from 'react' ; const useMobileCheck = ( maxWidth ) => { const [ isMobile , setMobile ] = React . useState < boolean > ( false ) ; React . useEffect ( ( ) => { if ( window . matchMedia ) { const query = window . matchMedia ( `(max-width: ${ maxWidth })` ) ; const setMobileFromQuery = ( q ) => setMobile ( q . matches ) ; query . removeListener ( setMobileFromQuery as any ) ; query . addListener ( setMobileFromQuery as any ) ; setMobileFromQuery ( query ) ; return ( ) => query . removeListener ( setMobileFromQuery as any ) ; } return undefined ; } , [ ] ) ; return isMobile ; } ; export default useMobileCheck ;