mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-30 16:17:41 +01:00
add horizontal check to isMobile helper
This commit is contained in:
parent
a2e5e08b20
commit
35adaf3872
1 changed files with 5 additions and 3 deletions
|
@ -1,12 +1,14 @@
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
export function useIsMobile() {
|
export function useIsMobile(horizontal?: boolean) {
|
||||||
const [isMobile, setIsMobile] = useState(false);
|
const [isMobile, setIsMobile] = useState(false);
|
||||||
const isMobileCurrent = useRef<boolean | null>(false);
|
const isMobileCurrent = useRef<boolean | null>(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function onResize() {
|
function onResize() {
|
||||||
const value = window.innerWidth < 1024;
|
const value = horizontal
|
||||||
|
? window.innerHeight < 600
|
||||||
|
: window.innerWidth < 1024;
|
||||||
const isChanged = isMobileCurrent.current !== value;
|
const isChanged = isMobileCurrent.current !== value;
|
||||||
if (!isChanged) return;
|
if (!isChanged) return;
|
||||||
|
|
||||||
|
@ -20,7 +22,7 @@ export function useIsMobile() {
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener("resize", onResize);
|
window.removeEventListener("resize", onResize);
|
||||||
};
|
};
|
||||||
}, []);
|
}, [horizontal]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isMobile,
|
isMobile,
|
||||||
|
|
Loading…
Reference in a new issue