Skip to content

Commit 1b7ee56

Browse files
GRACENOBLEclaude
andcommitted
fix(web): resolve CI lint failures in use-mobile hook and image mock
- Move initial isMobile read into useState initializer to avoid calling setState synchronously inside useEffect body - Suppress @next/next/no-img-element warning in test mock (intentional) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f62883e commit 1b7ee56

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎web/__mocks__/next/image.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ImageProps } from 'next/image'
22

33
export default function MockImage({ src, alt, width, height, ...props }: ImageProps) {
44
return (
5+
// eslint-disable-next-line @next/next/no-img-element
56
<img
67
src={typeof src === 'string' ? src : ''}
78
alt={alt}

‎web/hooks/use-mobile.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ import * as React from "react"
33
const MOBILE_BREAKPOINT = 768
44

55
export function useIsMobile() {
6-
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
6+
const [isMobile, setIsMobile] = React.useState(
7+
() => typeof window !== "undefined" && window.innerWidth < MOBILE_BREAKPOINT,
8+
)
79

810
React.useEffect(() => {
911
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
10-
const onChange = () => {
11-
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
12-
}
12+
const onChange = () => setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
1313
mql.addEventListener("change", onChange)
14-
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
1514
return () => mql.removeEventListener("change", onChange)
1615
}, [])
1716

18-
return !!isMobile
17+
return isMobile
1918
}

0 commit comments

Comments
 (0)