> For the complete documentation index, see [llms.txt](https://minwork.gitbook.io/long-press-hook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://minwork.gitbook.io/long-press-hook/advanced/options/callbacks.md).

# Callbacks

Long press lifecycle callbacks

## Structure

All callbacks (including [main callback](/long-press-hook/advanced/callback.md) function) has the same structure.

{% code title="Pseudocode" %}

```javascript
callbackFn(event, meta): void
```

{% endcode %}

{% code title="TypeScript" %}

```ts
type LongPressCallback<Target extends Element = Element, Context = unknown> = (
  event: LongPressEvent<Target>,
  meta: LongPressCallbackMeta<Context>
) => void
```

{% endcode %}

As a first argument callback receives [React event](/long-press-hook/advanced/options/react-events.md) from a proper [handler](/long-press-hook/advanced/hook-result-bind-function/handlers.md) (e.g. `onMouseDown`) and as second receives *meta* object with following structure:

*Pseudocode*

{% code title="Pseudocode" %}

```
{ [context: any], [reason: string] }
```

{% endcode %}

{% code title="TypeScript" %}

```ts
export type LongPressCallbackMeta<Context = unknown> = { 
    context?: Context; 
    reason?: LongPressCallbackReason 
};
```

{% endcode %}

Both object properties are optional.

### Context

`context` will be present if you pass it to [bind function](/long-press-hook/advanced/hook-result-bind-function.md). See [context](/long-press-hook/advanced/hook-result-bind-function/context.md) for more info.

### Reason

`reason` will be present in [onCancel](/long-press-hook/advanced/options/callbacks/long-press-cancelled.md) callback to indicate why long press was cancelled.&#x20;

Here is a list of all possible *reason* values

{% code title="Javascript" %}

```javascript
'cancelled-by-movement' | 'cancelled-by-release' | 'cancelled-outside-element'
```

{% endcode %}

{% code title="TypeScript" %}

```typescript
export enum LongPressCallbackReason {
  /**
   * Returned when mouse / touch / pointer was moved outside initial press area when _cancelOnMovement_ is active
   */
  CancelledByMovement = 'cancelled-by-movement',
  /**
   * Returned when click / tap / point was released before long press detection time threshold
   */
  CancelledByRelease = 'cancelled-by-release',
  /**
   * Returned when mouse / touch / pointer was moved outside element and _cancelOutsideElement_ option was set to `true`
   */
  CancelledOutsideElement = 'cancelled-outside-element',
}
```

{% endcode %}

{% content-ref url="/pages/DH9Dkq8FDrcGrmvCGsy6" %}
[Press started](/long-press-hook/advanced/options/callbacks/press-started.md)
{% endcontent-ref %}

{% content-ref url="/pages/H53ZOugpHRTiTcxyxMXc" %}
[On move](/long-press-hook/advanced/options/callbacks/on-move.md)
{% endcontent-ref %}

{% content-ref url="/pages/tk6zZE8evpkBxIWcngin" %}
[Press finished](/long-press-hook/advanced/options/callbacks/press-finished.md)
{% endcontent-ref %}

{% content-ref url="/pages/d0OSrGcKIx0MLgsJStv5" %}
[Long press cancelled](/long-press-hook/advanced/options/callbacks/long-press-cancelled.md)
{% endcontent-ref %}
