> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monad.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# 如何为 Farcaster Mini App 添加 haptics

Haptics 是一种为应用添加触觉反馈的方式,可以增强用户交互和响应性。

本指南将带您在 Farcaster Mini App 中实现 haptics,为用户提供更直观、更有吸引力的体验。

## 在 Farcaster Mini App 中实现 haptics

如果您使用的是 [Monad Mini App 模板](https://github.com/monad-developers/monad-miniapp-template/tree/main),可以使用来自 [useFrame](https://github.com/monad-developers/monad-miniapp-template/blob/main/components/farcaster-provider.tsx) hook 的 `haptics`。

如果您没有使用 Monad Mini App 模板,可以查看 [useFrame](https://github.com/monad-developers/monad-miniapp-template/blob/main/components/farcaster-provider.tsx) hook 来了解实现细节。

以下是在 Farcaster Mini App 中实现 haptics 的示例:

```tsx theme={null}
...

export default function MyComponent() {
  const { haptics } = useFrame();

  return (
    <div>
      <button onClick={() => haptics.impactOccurred('light')}>Light Impact</button>
    </div>
  );
}
```

## 支持的 haptics

支持以下 haptics:

| Haptic 类型            | 代码                                        |
| -------------------- | ----------------------------------------- |
| Light Impact         | `haptics.impactOccurred('light')`         |
| Medium Impact        | `haptics.impactOccurred('medium')`        |
| Heavy Impact         | `haptics.impactOccurred('heavy')`         |
| Soft Impact          | `haptics.impactOccurred('soft')`          |
| Rigid Impact         | `haptics.impactOccurred('rigid')`         |
| Success Notification | `haptics.notificationOccurred('success')` |
| Warning Notification | `haptics.notificationOccurred('warning')` |
| Error Notification   | `haptics.notificationOccurred('error')`   |
| Selection Change     | `haptics.selectionChanged()`              |
