mirror of
https://github.com/linsa-io/linsa.git
synced 2026-04-23 16:58:38 +02:00
Move to TanStack Start from Next.js (#184)
This commit is contained in:
27
web/app/hooks/use-touch-sensor.ts
Normal file
27
web/app/hooks/use-touch-sensor.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import * as React from "react"
|
||||
import { isClient } from "~/lib/utils"
|
||||
|
||||
export function useTouchSensor() {
|
||||
const [isTouchDevice, setIsTouchDevice] = React.useState(false)
|
||||
|
||||
React.useEffect(() => {
|
||||
const detectTouch = () => {
|
||||
setIsTouchDevice(
|
||||
isClient() &&
|
||||
(window.matchMedia?.("(hover: none) and (pointer: coarse)")
|
||||
?.matches ||
|
||||
"ontouchstart" in window ||
|
||||
navigator.maxTouchPoints > 0),
|
||||
)
|
||||
}
|
||||
|
||||
detectTouch()
|
||||
window.addEventListener("touchstart", detectTouch, false)
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("touchstart", detectTouch)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return isTouchDevice
|
||||
}
|
||||
Reference in New Issue
Block a user