From 35adaf38721487b7cbbacdadf183be2002c3061b Mon Sep 17 00:00:00 2001 From: Max Ward Date: Sun, 19 Feb 2023 22:25:49 -0800 Subject: [PATCH] add horizontal check to isMobile helper --- src/hooks/useIsMobile.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hooks/useIsMobile.ts b/src/hooks/useIsMobile.ts index a336afdb..a2df937f 100644 --- a/src/hooks/useIsMobile.ts +++ b/src/hooks/useIsMobile.ts @@ -1,12 +1,14 @@ import { useEffect, useRef, useState } from "react"; -export function useIsMobile() { +export function useIsMobile(horizontal?: boolean) { const [isMobile, setIsMobile] = useState(false); const isMobileCurrent = useRef(false); useEffect(() => { function onResize() { - const value = window.innerWidth < 1024; + const value = horizontal + ? window.innerHeight < 600 + : window.innerWidth < 1024; const isChanged = isMobileCurrent.current !== value; if (!isChanged) return; @@ -20,7 +22,7 @@ export function useIsMobile() { return () => { window.removeEventListener("resize", onResize); }; - }, []); + }, [horizontal]); return { isMobile,