Files
claude-code/web/hooks/useMediaQuery.ts
nirholas 3a854557e0
Some checks failed
CI / Typecheck & Lint (push) Has been cancelled
feat: implement API key authentication and user session management
2026-03-31 12:43:05 +00:00

33 lines
819 B
TypeScript
Raw Permalink 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)");
}