mirror of
https://github.com/Since-3/since3-portal.git
synced 2026-10-12 19:51:17 +00:00
21 lines
523 B
TypeScript
21 lines
523 B
TypeScript
import * as React from "react"
|
|
|
|
const MOBILE_BREAKPOINT = 768
|
|
|
|
function subscribe(callback: () => void) {
|
|
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
|
mql.addEventListener("change", callback)
|
|
return () => mql.removeEventListener("change", callback)
|
|
}
|
|
|
|
function getSnapshot() {
|
|
return window.innerWidth < MOBILE_BREAKPOINT
|
|
}
|
|
|
|
function getServerSnapshot() {
|
|
return false
|
|
}
|
|
|
|
export function useIsMobile() {
|
|
return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)
|
|
}
|