usePressTap
A hook that manages press/tap interaction state of Lynx elements.
Installation
Import
usePressTap is a standalone package that can be used without styles. You can use it without installing @seed-design/lynx-react.
The existing usePressTap re-export from @seed-design/lynx-react is also maintained. For new code, it is recommended to import directly from the standalone package above.
Usage
Basic Usage
Disabled State
If disabled changes to true while pressing, pressed is released and tap handling on both threads is blocked.
Main Thread Events
API
Options
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | When true, press state changes and the tap event are blocked. |
onTap | EventHandler<BaseTouchEvent<Target>> | - | Receives the Background Thread's tap event as-is. |
mainThreadOnTap | IntrinsicElements["view"]["main-thread:bindtap"] | - | A callback that requires the "main thread" directive. Not bound when disabled. |
Return
| Property | Type | Description |
|---|---|---|
pressed | boolean | The current press state. |
bindtap | EventHandler<BaseTouchEvent<Target>> | The tap event handler. |
bindtouchstart | EventHandler<BaseTouchEvent<Target>> | The touch start handler. |
bindtouchend | EventHandler<BaseTouchEvent<Target>> | The touch end handler. |
bindtouchcancel | EventHandler<BaseTouchEvent<Target>> | The touch cancel handler. |
main-thread:bindtap | IntrinsicElements["view"]["main-thread:bindtap"] | The main thread tap handler. Not included when disabled is set or mainThreadOnTap is not provided. |
State and Styling
Spread the return value except pressed onto the native element. pressed is a transient pressed state that turns on at touch start and releases on touch end/cancel/tap or when disabled. It differs from a toggle state that persists a selection.
The hook itself does not apply any CSS class or style. In UI you build yourself, you can choose a className that matches pressed. Don't assume that an existing Crispy component's Recipe provides a pressed variant. Immediate visual feedback on the Main Thread is distinct from the :active or ScaleFeedback path a component uses.
If you overwrite a user handler added to the same bindtap etc. afterward, the hook's own handling disappears. Call both the hook's handler and the user action together in a single handler, or pass tap side effects through onTap.
Differences from the Web
- Uses Lynx's
bindtap·bindtouchstart/end/cancelinstead of DOM'sonClick·pointer events. - This hook does not provide hover/focus state, keyboard input, or accessibility attributes. Configure these separately in the consuming component.
- If you provide
mainThreadOnTap, the Main Thread handler is also returned. If you specify both callbacks, each runs on its own thread, so make sure you don't handle the same side effect twice.