| 1 | "use client"; |
| 2 | |
| 3 | import * as React from "react"; |
| 4 | |
| 5 | export function useIsTouchDevice() { |
| 6 | const [isTouchDevice, setIsTouchDevice] = React.useState(false); |
| 7 | |
| 8 | React.useEffect(() => { |
| 9 | function onResize() { |
| 10 | setIsTouchDevice( |
| 11 | "ontouchstart" in window || |
| 12 | navigator.maxTouchPoints > 0 || |
| 13 | navigator.maxTouchPoints > 0, |
| 14 | ); |
| 15 | } |
| 16 | |
| 17 | window.addEventListener("resize", onResize); |
| 18 | onResize(); |
| 19 | |
| 20 | return () => { |
| 21 | window.removeEventListener("resize", onResize); |
| 22 | }; |
| 23 | }, []); |
| 24 | |
| 25 | return isTouchDevice; |
| 26 | } |
| 27 |