2.0.0 • Published 4 months ago

@greenlabs/rescript-hammerjs v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

rescript-hammerjs

ReScript binding of @egjs/hammerjs

Install

npm i @greenlabs/rescript-hammerjs
or
yarn add @greenlabs/rescript-hammerjs
"bs-dependencies": [
  "@greenlabs/rescript-hammerjs"
]

Usage

React.useEffect0(_ => {
    let swipeInstance =
      ref.current
      ->Js.Nullable.toOption
      ->Option.mapWithDefault(None, el => Some(el->HammerJs.makeWithElement))

    swipeInstance->Option.forEach(swipeInstance' =>
      HammerJs.on(
        swipeInstance',
        #swipe,
        event => {
          Js.log(event)
        },
      )
    )

    Some(
      _ => {
        swipeInstance->Option.forEach(swipeInstance' => swipeInstance'->HammerJs.destroy)
      },
    )
  })