mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-05-31 18:24:10 +00:00
16 lines
502 B
TypeScript
16 lines
502 B
TypeScript
|
|
import { useEffect, useState } from 'react';
|
||
|
|
|
||
|
|
const MOBILE_BREAKPOINT_PX = 768;
|
||
|
|
|
||
|
|
export function useMediaQuery(breakpoint: number = MOBILE_BREAKPOINT_PX) {
|
||
|
|
const [isMobile, setIsMobile] = useState<boolean>(() => window.innerWidth <= breakpoint);
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
const onResize = () => setIsMobile(window.innerWidth <= breakpoint);
|
||
|
|
window.addEventListener('resize', onResize);
|
||
|
|
return () => window.removeEventListener('resize', onResize);
|
||
|
|
}, [breakpoint]);
|
||
|
|
|
||
|
|
return { isMobile };
|
||
|
|
}
|