UseIsTouchDevice
guarahooks/use-is-touch-deviceFreeHook
Hook to detect if the user's device has touch screen functionality.
Install it
npx shadcn@latest add https://guarahooks.com/r/use-is-touch-device.jsonSource
1'use client';23import { useEffect, useState } from 'react';45interface UseIsTouchDeviceReturn {6 isTouchable: boolean;7}89export function useIsTouchDevice(): UseIsTouchDeviceReturn {10 const [isTouchable, setIsTouchable] = useState<boolean>(false);1112 useEffect(() => {13 if (typeof window === 'undefined' || typeof navigator === 'undefined') {14 return;15 }1617 // Check for touch support using multiple methods for better compatibility18 const hasTouch =19 'ontouchstart' in window ||20 navigator.maxTouchPoints > 0 ||21 // Legacy support for older browsers22 ('msMaxTouchPoints' in navigator &&23 (navigator as any).msMaxTouchPoints > 0);2425 setIsTouchable(hasTouch);26 }, []);2728 return {29 isTouchable,30 };31}
Files it writes
More from guarahooks
All 100 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| UseAbortControlleruse-abort-controller | guarahooks | Hooks | Free | no deps | |
| UseArrayStateuse-array-state | guarahooks | Hooks | Free | no deps | |
| UseAxiosuse-axios | guarahooks | Hooks | Free | no deps | |
| UseBatteryStatususe-battery-status | guarahooks | Hooks | Free | no deps | |
| UseBetterAuthuse-better-auth | guarahooks | Hooks | Free | no deps | |
| UseClickOutsideuse-click-outside | guarahooks | Hooks | Free | no deps | |
| UseConfirmuse-confirm | guarahooks | Hooks | Free | no deps | |
| UseCookieuse-cookie | guarahooks | Hooks | Free | no deps |
