Files
codeaashu-claude-code/web/hooks/useMediaQuery.ts
ashutoshpythoncs@gmail.com b564857c0b claude-code
2026-03-31 18:58:05 +05:30

33 lines
819 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { useState, useEffect } from "react";
export function useMediaQuery(query: string): boolean {
const [matches, setMatches] = useState(false);
useEffect(() => {
const mq = window.matchMedia(query);
setMatches(mq.matches);
const handler = (e: MediaQueryListEvent) => setMatches(e.matches);
mq.addEventListener("change", handler);
return () => mq.removeEventListener("change", handler);
}, [query]);
return matches;
}
/** < 768px */
export function useIsMobile(): boolean {
return useMediaQuery("(max-width: 767px)");
}
/** 768px 1023px */
export function useIsTablet(): boolean {
return useMediaQuery("(min-width: 768px) and (max-width: 1023px)");
}
/** >= 1024px */
export function useIsDesktop(): boolean {
return useMediaQuery("(min-width: 1024px)");
}