create a useismobilewidth method for standardized mobile view detection.

This commit is contained in:
sabaimran
2024-08-07 21:04:44 +05:30
parent 2943bed5d4
commit f28693c8c7
12 changed files with 48 additions and 127 deletions

View File

@@ -1,3 +1,4 @@
import { useEffect, useState } from "react";
import useSWR from "swr";
export interface LocationData {
@@ -54,3 +55,23 @@ export function useIPLocationData() {
return locationData;
}
export function useIsMobileWidth() {
const [isMobileWidth, setIsMobileWidth] = useState(false);
useEffect(() => {
const handleResize = () => {
if (window.innerWidth <= 768) {
setIsMobileWidth(true);
} else {
setIsMobileWidth(false);
}
};
handleResize();
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}, []);
return isMobileWidth;
}