Files
cunkebao_v3/Cunkebao/hooks/use-mobile.tsx
笔记本里的永平 5ff15472f5 feat: 本次提交更新内容如下
场景获客列表搞定
2025-07-07 17:08:27 +08:00

29 lines
599 B
TypeScript

"use client"
import { useState, useEffect } from "react"
const MOBILE_MAX_WIDTH = 768 // Adjust as needed
export function useMobile() {
const [isMobile, setIsMobile] = useState(false)
useEffect(() => {
const checkScreenSize = () => {
setIsMobile(window.innerWidth <= MOBILE_MAX_WIDTH)
}
// Initial check
checkScreenSize()
// Subscribe to the window resize event
window.addEventListener("resize", checkScreenSize)
// Unsubscribe on unmount
return () => {
window.removeEventListener("resize", checkScreenSize)
}
}, [])
return isMobile
}