18 lines
470 B
TypeScript
18 lines
470 B
TypeScript
import { useEffect, useState } from "react";
|
|
|
|
export default function useDevice() {
|
|
const [isMobile, setIsMobile] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const checkIsMobile = () => {
|
|
setIsMobile(window.innerWidth < 768);
|
|
};
|
|
|
|
checkIsMobile();
|
|
window.addEventListener("resize", checkIsMobile);
|
|
return () => window.removeEventListener("resize", checkIsMobile);
|
|
}, []);
|
|
|
|
return isMobile;
|
|
}
|