add horizontal check to isMobile helper

This commit is contained in:
Max Ward 2023-02-19 22:25:49 -08:00
parent a2e5e08b20
commit 35adaf3872

View File

@ -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<boolean | null>(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,