useHaptics
Selection, impact and notification haptics with an off switch.
Selection, impact and notification haptics from expo-haptics, with an off switch that components wire to their haptics prop.
Free (MIT)Version 1.1.0Released 26 Oct 2026iOS and Android
When to use it
- Add selection, impact or outcome feedback to an explicit interaction.
When not to use it
- Use visible state and screen-reader feedback as the primary signal; haptics are optional.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add use-haptics- Adds
components/swipeui/hooks/use-haptics.tsand 2 shared helpers. - Installs expo-haptics, react-native-reanimated, react-native-worklets, uniwind. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { useHaptics } from '@/components/swipeui/hooks/use-haptics';
function SaveButton({ haptics = true, onPress }: { haptics?: boolean; onPress: () => void }) {
const feedback = useHaptics(haptics);
return <Pressable onPress={() => (feedback.impact(), onPress())} />;
}Pass a component's haptics prop straight through, so people using it can turn feedback off.
| Call | Use for |
|---|---|
selection() | Changing a selection: tabs, segments, switches |
impact(style?) | Pressing something. style is light (default), medium, heavy, soft or rigid |
notification(type) | The outcome of a task: success, warning or error |
Returns
| Prop | Type | Default | Description |
|---|---|---|---|
enabled | | — | Whether feedback plays. |
selection | | — | A light tick for changing a selection, such as switching tabs or segments. |
impact | | | A tap for pressing something. |
notification | | — | The outcome of a task, such as a purchase succeeding or failing. |
Gotchas
- Calls never throw. Devices without a haptic engine (and simulators) stay silent.
- It wraps
expo-haptics, which Expo Go includes. In a development build or a bare app, rebuild after the CLI installs it.
Accessibility
- Do not rely on haptics alone; callers can disable them.
Motion
- Static on its own; any movement comes from the parent that animates it.
- No custom movement is configured by this item.
Performance
- Calls the native feedback API on demand; unavailable feedback is ignored.
Notes for AI
- The preset supplies the default impact style; a local style still wins. Global off and the enabled argument suppress all feedback.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.