@awsui/components-react
Version:
AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A
22 lines (21 loc) • 669 B
JavaScript
import { useEffect, useState } from 'react';
import { getMatchingBreakpoint } from '../../breakpoints';
function getIsMobile() {
if (typeof window === 'undefined') {
return false;
}
return getMatchingBreakpoint(window.innerWidth, ['xs']) !== 'xs';
}
export function useMobile() {
var _a = useState(getIsMobile()), isMobile = _a[0], setMobile = _a[1];
function handleResize() {
setMobile(getIsMobile());
}
useEffect(function () {
window.addEventListener('resize', handleResize);
return function () {
window.removeEventListener('resize', handleResize);
};
}, []);
return isMobile;
}