From 87a83a5604b20550430ef4eefbcd573d309694e2 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Sun, 22 Jun 2025 10:02:50 +0200 Subject: Initial commit --- apps/web/src/hooks/use-mobile.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 apps/web/src/hooks/use-mobile.tsx (limited to 'apps/web/src/hooks/use-mobile.tsx') diff --git a/apps/web/src/hooks/use-mobile.tsx b/apps/web/src/hooks/use-mobile.tsx new file mode 100644 index 00000000..2b0fe1df --- /dev/null +++ b/apps/web/src/hooks/use-mobile.tsx @@ -0,0 +1,19 @@ +import * as React from "react" + +const MOBILE_BREAKPOINT = 768 + +export function useIsMobile() { + const [isMobile, setIsMobile] = React.useState(undefined) + + React.useEffect(() => { + const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`) + const onChange = () => { + setIsMobile(window.innerWidth < MOBILE_BREAKPOINT) + } + mql.addEventListener("change", onChange) + setIsMobile(window.innerWidth < MOBILE_BREAKPOINT) + return () => mql.removeEventListener("change", onChange) + }, []) + + return !!isMobile +} -- cgit v1.3.1