Files
zellyy-finance/src/hooks/use-mobile.tsx
gpt-engineer-app[bot] 87a6a65f17 Fix dialog rounded corners on mobile
The dialog's rounded corners were not displaying correctly on mobile devices, while they were fine on desktop. This commit addresses the issue.
2025-03-16 06:10:57 +00:00

37 lines
933 B
TypeScript

import * as React from "react"
const MOBILE_BREAKPOINT = 768
export function useIsMobile() {
const [isMobile, setIsMobile] = React.useState<boolean>(
typeof window !== 'undefined' ? window.innerWidth < MOBILE_BREAKPOINT : false
)
React.useEffect(() => {
if (typeof window === 'undefined') return;
const checkMobile = () => {
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
// 모바일 화면인 경우 body에 클래스 추가
if (window.innerWidth < MOBILE_BREAKPOINT) {
document.body.classList.add('is-mobile');
} else {
document.body.classList.remove('is-mobile');
}
}
// 초기 확인
checkMobile()
// 리사이즈 이벤트 리스너 추가
window.addEventListener('resize', checkMobile)
// 클린업 함수
return () => window.removeEventListener('resize', checkMobile)
}, [])
return isMobile
}