UNPKG

jobiqo-cl

Version:

[![CircleCI](https://circleci.com/gh/jobiqo/jobiqo-cl.svg?style=svg&circle-token=5a24efa5b8bbc4879276123e77d0d3f35ca7144c)](https://circleci.com/gh/jobiqo/jobiqo-cl)

31 lines (28 loc) 829 B
import { useState, useEffect } from 'react'; /** * @file index.tsx * * @fileoverview Help determine if the user is in mobile using matchmedia. */ const useIsMobile = theme => { const isClient = typeof window === 'object'; const [isMobile, setIsMobile] = useState(true); function getIsMobile() { if (isClient && window.matchMedia(`(max-width: ${theme.breakpoints[0]})`).matches) { setIsMobile(true); } else { setIsMobile(false); } } useEffect(() => { getIsMobile(); window.addEventListener('resize', handleResize); return () => window.removeEventListener('resize', handleResize); }, []); function handleResize() { getIsMobile(); } return isMobile; }; export { useIsMobile };