Long press hook
  • Introduction
  • Installation
  • Basics
  • Advanced
    • Definition
    • Callback
    • Options
      • Configuration
        • Events detection
        • Long press threshold
      • React events
        • Persisting event
        • Filtering events
      • Callbacks
        • Press started
        • On move
        • Press finished
        • Long press cancelled
      • Cancellation
        • Cancel outside element
        • Cancel on movement
    • Hook result / Bind function
      • Context
      • Handlers
  • Examples
    • Advanced usage example
    • Live examples
      • Version 3
      • Version 2 (deprecated)
      • Version 1 (deprecated)
  • Migration
    • V1 to V2
    • V2 to V3
    • ⚠️V3.1+
    • Change log
  • Contributions
    • ❤️Donations
    • Pull requests policy
  • Architectural Decisions
    • V1 and V2 deprecation
    • Moving to new repository
Powered by GitBook
On this page
  • [BREAKING CHANGE] Drop support for 'both' option in detect param
  • Before
  • After
  • [BREAKING CHANGE] Typings and param values

Was this helpful?

  1. Migration

V2 to V3

[BREAKING CHANGE] Drop support for 'both' option in detect param

Returning both mouse and touch handlers as a hook result caused unintended edge cases on touch devices that emulated clicks. Therefore 'both' value was removed and hook is now using 'pointer' as a default value for detect param.

This also enables to support more type of events in the future.

Pointer events should be sufficient replacement for 'both' option, but you can also programmatically detect if current device support touch events and set proper detect value based on that.

Before

const bind = useLongPress(() => console.log('Long pressed'), {
  detect: 'both',
})

After

const bind = useLongPress(() => console.log('Long pressed'), {
  detect: 'pointer',
})

[BREAKING CHANGE] Typings and param values

TypeScript's typings were refactored to use more consistent and precise names. Also changed callback reason values (see LongPressEventReason)

  • Changed generics order from useLongPress<Target, Callback, Context> to useLongPress<Target, Context, Callback>

  • Renamed LongPressDetectEvents enum to LongPressEventType

    • LongPressDetectEvents.MOUSE -> LongPressEventType.Mouse

    • LongPressDetectEvents.TOUCH -> LongPressEventType.Touch

  • Added LongPressEventType.Pointer

  • Renamed LongPressEventReason enum to LongPressCallbackReason

    • LongPressEventReason.CANCELED_BY_MOVEMENT ('canceled-by-movement') -> LongPressCallbackReason.CancelledByMovement ('cancelled-by-movement')

    • LongPressEventReason.CANCELED_BY_TIMEOUT ('canceled-by-timeout') -> LongPressCallbackReason.CancelledByRelease ('cancelled-by-release')

  • Removed Coordinates type

  • Renamed EmptyObject type to LongPressEmptyHandlers

  • Renamed CallableContextResult type to LongPressResult

  • Renamed LongPressResult type to LongPressHandlers

  • Added mouse and touch handlers types - LongPressMouseHandlers and LongPressTouchHandlers

PreviousV1 to V2NextV3.1+

Last updated 1 year ago

Was this helpful?