MCPcopy
hub / github.com/dubinc/dub / useMediaQuery

Function useMediaQuery

packages/ui/src/hooks/use-media-query.ts:19–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17}
18
19export function useMediaQuery() {
20 const [device, setDevice] = useState<"mobile" | "tablet" | "desktop" | null>(
21 getDevice(),
22 );
23 const [dimensions, setDimensions] = useState<{
24 width: number;
25 height: number;
26 } | null>(getDimensions());
27
28 useEffect(() => {
29 const checkDevice = () => {
30 setDevice(getDevice());
31 setDimensions(getDimensions());
32 };
33
34 // Initial detection
35 checkDevice();
36
37 // Listener for windows resize
38 window.addEventListener("resize", checkDevice);
39
40 // Cleanup listener
41 return () => {
42 window.removeEventListener("resize", checkDevice);
43 };
44 }, []);
45
46 return {
47 device,
48 width: dimensions?.width,
49 height: dimensions?.height,
50 isMobile: device === "mobile",
51 isTablet: device === "tablet",
52 isDesktop: device === "desktop",
53 };
54}

Callers 15

PopoverFunction · 0.90
LinkPreviewFunction · 0.90
ModalFunction · 0.90
UTMBuilderFunction · 0.90
ComboboxFunction · 0.90
FunnelChartInnerFunction · 0.90
FilterSelectFunction · 0.90
DateRangePickerInnerFunction · 0.90
PasswordFormFunction · 0.90
FormFunction · 0.90
DashboardPasswordFormFunction · 0.90
LinkBuilderFunction · 0.90

Calls 3

getDeviceFunction · 0.85
getDimensionsFunction · 0.85
checkDeviceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…