Files
basiclean-webapp/hooks/useIsDesktop.ts
2026-05-03 11:07:55 +02:00

23 lines
483 B
TypeScript

"use client";
import { useEffect, useState } from "react";
export function useIsDesktop(breakpoint = 1024) {
const [isDesktop, setIsDesktop] = useState(false);
useEffect(() => {
const mql = window.matchMedia(`(min-width: ${breakpoint}px)`);
const update = () => setIsDesktop(mql.matches);
update();
mql.addEventListener("change", update);
return () => {
mql.removeEventListener("change", update);
};
}, [breakpoint]);
return isDesktop;
}