Error in ReasonReact.wrapReasonForJs with jsProps

interop
reasonreact

#1

Hello, community!

I am having a problem using a ReasonReact component with Gatsby and the Netlify CMS. It is a reducerComponent, and was working fine until I tried to add props. Now I am having this error:

  190 │ 
  191 │ let default =ReasonReact.wrapReasonForJs(~component, jsProps =>
  192 │     make(
  193 │       ~holidays=jsProps->holidaysGet,
  194 │       [||],
  
  This function has type
    'a =>
    ReasonReact.componentSpec(state, state, ReasonReact.noRetainedProps,
                               ReasonReact.noRetainedProps, action)
  It only accepts 1 argument; here, it's called with more.

The code looks like this:

type holiday = {
  title: string,
  body: string,
  date: string,
  holiday_type: string,
}

let component = ReasonReact.reducerComponent("Calendar");

let str = ReasonReact.string;

[@bs.deriving abstract]
type jsProps = {
  holidays: list(holiday),
};
...
let make = _children => {
...
};

let default =ReasonReact.wrapReasonForJs(~component, jsProps =>
    make(
      ~holidays=jsProps->holidaysGet,
      [||],
    )
  );

That’s troubling because I copied the code directly from the docs https://reasonml.github.io/reason-react/docs/en/interop , only changed the prop name.

Do you know what I missed?

And on a related matter, once this works, how can I use the prop in the ReasonReact component? Can’t find documentation on this, in the docs, the type jsProps is defined after the component make function, but I want to use the prop to display stuff in it. How?

Thanks in advance for your time!


#2

This is happening because you are not passing the value to your make function. The error is correct but it’s not informative. You are only passing _children to make but you should be passing ~holidays before it.

Once you pass ~holidays to your component you should be able to use it as an array type. So You would map over it as an array.

An article I wrote might help you with this: https://medium.com/@arecvlohe/convert-a-js-object-to-a-reason-record-in-reasonreact-f997f449d6aa


#3

Wow cool, thanks! Yeah it builds now. And great article, BTW! That’s exactly what I needed to understand how to use the props once the bug was fixed. This step and and subsequent usage are kind of overlooked in the docs, or maybe it’s obvious for the initiated.

Thanks again!