useHaptics
Safe tactile feedback hook supporting light, medium, heavy, and notification haptics with web/unsupported fallback.
v0.1.1NativeWindStyleSheetiOSAndroidExpo Go
Installation
npx nativra-cli add use-hapticsWrites use-haptics.ts to hooks, rewrites imports to your aliases and records hashes in nativra.lock.json. Existing files are never overwritten without asking.
Want to try it first? Open it in the playground: a real React Native project in your browser, with this item installed by the CLI.
Usage
The useHaptics hook triggers tactile haptic vibrations on iOS and Android devices via expo-haptics. It gracefully falls back to a no-op on Web or in environments where hardware vibration is unsupported.
Installation
npx nativra add use-hapticsUsage
import { Pressable, Text } from "react-native";
import { useHaptics } from "@/hooks/use-haptics";
export function HapticButton() {
const { trigger } = useHaptics();
return (
<Pressable
onPress={() => trigger("medium")}
className="h-11 px-5 rounded-xl bg-zinc-900 items-center justify-center"
>
<Text className="text-white font-medium">Tap with Haptics</Text>
</Pressable>
);
}Source
Exactly what the CLI writes, before your import aliases are applied.
Dependencies
npm packages
- expo-haptics>=13.0.0peer