> 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/migration/v1-to-v2.md).

# V1 to V2

## \[BREAKING CHANGE] Context support

Now hook returns function which can be called with any context in order to access it in callbacks

### *Before*

```tsx
const bind = useLongPress(() => console.log('Long pressed'));
// ...
return <button {...bind}>Click me</button>;
```

### *After*

```tsx
const bind = useLongPress((event, { context }) => console.log('Long pressed with', context));
// ...
return <button {...bind('I am context')}>Click me</button>;
// Or just empty function call if you don't want to pass any context
return <button {...bind()}>Click me</button>;
```

## \[NEW] Reason for cancellation

Now `onCancel` receives cancellation context which can be either:

* `LongPressEventReason.CANCELED_BY_TIMEOUT` (`'canceled-by-timeout'`)
* `LongPressEventReason.CANCELED_BY_MOVEMENT` (`'canceled-by-movement'`)

You can access it like this:

```tsx
const bind = useLongPress(() => console.log('Long pressed'), {
  onCancel: (event, { reason }) => console.log('Cancellation reason:', reason) 
})
```
