How to create bindings for this React Hook?

Hi everyone!

There is a hook that receives a record and returns a function that will be passed to a component.

I wrote it down like this:

   external useAnimatedScrollHandler: handlers => @uncurry (Event.scrollEvent => unit) =
     "useAnimatedScrollHandler" 

And used it

  let scrollHandler = useAnimatedScrollHandler({
      onScroll: event => {
        translationY.value = event.contentOffset.y
      },
    })

Generating this JS:

  var partial_arg_onScroll = (function ($$event) {
      translationY.value = $$event.contentOffset.y;
    });
  var partial_arg = {
    onScroll: partial_arg_onScroll
  };
  var scrollHandler = function (param) {
    ReactNativeReanimated.useAnimatedScrollHandler(partial_arg, param);
  };

Violating hooks rule to start with “use” 😮‍💨
I’m not sure if I’m using the @uncurry correctly btw

Playground
. can be used.

external useAnimatedScrollHandler: (int, . int) => unit =
  "useAnimatedScrollHandler"

let scrollHandler = useAnimatedScrollHandler(5)
1 Like