MCPcopy Create free account
hub / github.com/code-forge-io/react-router-devtools / useMobileView

Function useMobileView

docs/app/hooks/use-mobile-view.ts:7–21  ·  view source on GitHub ↗
(breakpoint = 1280)

Source from the content-addressed store, hash-verified

5 * Returns true if mobile, false otherwise.
6 */
7export function useMobileView(breakpoint = 1280) {
8 const [isMobile, setIsMobile] = useState<boolean | null>(() =>
9 typeof window === "undefined" ? null : window.innerWidth < breakpoint
10 )
11
12 useLayoutEffect(() => {
13 const mql = window.matchMedia(`(max-width: ${breakpoint}px)`)
14 const onChange = (e: MediaQueryListEvent) => setIsMobile(e.matches)
15 setIsMobile(mql.matches)
16 mql.addEventListener("change", onChange)
17 return () => mql.removeEventListener("change", onChange)
18 }, [breakpoint])
19
20 return { isMobile }
21}

Callers 1

SidebarContentFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…