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