Use has primary touch
optics/use-has-primary-touchFreeUtility
Hook utility: use-has-primary-touch
See it running
Open the demo on optics
optics.agusmayol.com.ar/components/use-has-primary-touchInstall it
npx shadcn@latest add https://optics.agusmayol.com.ar/r/use-has-primary-touch.jsonSource
1import { useEffect, useState } from "react";23export function useTouchPrimary() {4 const [isTouchPrimary, setIsTouchPrimary] = useState(false);56 useEffect(() => {7 if (typeof window === "undefined") return;89 const controller = new AbortController();10 const { signal } = controller;1112 const handleTouch = () => {13 const hasTouch = "ontouchstart" in window || navigator.maxTouchPoints > 0;14 const prefersTouch = window.matchMedia("(pointer: coarse)").matches;15 setIsTouchPrimary(hasTouch && prefersTouch);16 };1718 const mq = window.matchMedia("(pointer: coarse)");19 mq.addEventListener("change", handleTouch, { signal });20 window.addEventListener("pointerdown", handleTouch, { signal });2122 handleTouch();2324 return () => controller.abort();25 }, []);2627 return isTouchPrimary;28}
Files it writes
More from optics
All 79 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Cursor Rule: Back Endcursor-rule-back-end | optics | Utilities | Free | no deps | |
| Cursor Rule: Bulk Processingcursor-rule-bulk-processing | optics | Utilities | Free | no deps | |
| Cursor Rule: Commits Conventioncursor-rule-commits-convention | optics | Utilities | Free | no deps | |
| Cursor Rule: Front Endcursor-rule-front-end | optics | Utilities | Free | no deps | |
| Cursor Rule: Generalcursor-rule-general | optics | Utilities | Free | no deps | |
| Cursor Rule: React Optimizationcursor-rule-react-optimization | optics | Utilities | Free | no deps | |
| Cursor Rule: Web Interface Guidelinescursor-rule-web-interface-guidelines | optics | Utilities | Free | no deps | |
| Get strict contextget-strict-context | optics | Utilities | Free | no deps |
