SwipeUI
DocsHooks & utilities

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.ts and 2 shared helpers.
  • Installs expo-haptics, react-native-reanimated, react-native-worklets, uniwind. In Expo apps it uses npx expo install so versions match your SDK.

Usage

components/save-button.tsx
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.

CallUse 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

PropTypeDefaultDescription
enabledboolean—

Whether feedback plays.

selection() => void—

A light tick for changing a selection, such as switching tabs or segments.

impact(style?: ImpactStyle) => voidthe preset's style ('light' without a provider)

A tap for pressing something.

notification(type: NotificationType) => void—

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 onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items

On this page