ultisuite-client/hooks/use-md-breakpoint.ts
R3D347HR4Y 9266aa34cd huhu
2026-05-19 22:20:43 +02:00

24 lines
600 B
TypeScript

import { useLayoutEffect, useState } from "react"
export const MD_MIN_PX = 768
const MD_MQ = `(min-width: ${MD_MIN_PX}px)`
export function readMdMatches(): boolean {
if (typeof window === "undefined") return false
return window.matchMedia(MD_MQ).matches
}
export function useIsMd() {
const [matches, setMatches] = useState(false)
useLayoutEffect(() => {
const mql = window.matchMedia(MD_MQ)
const update = () => setMatches(mql.matches)
update()
mql.addEventListener("change", update)
return () => mql.removeEventListener("change", update)
}, [])
return matches
}