Redefining the React children prop and its behavior in a binding

Hello,

I was creating a binding to a JS React component library which requires an array of children even when there is one single child.

How can I redefine the children prop in the binding so that the generated javascript jsx representation considers children to be an array always. Or as per this example, I would like el1 to generate a children array even when there is one child.

My binding is something like and I want to redefine the type of the children field:

type props<'value> = {
  className?: string,
  children?: React.element,
  ...
}
@module("module_name")
external make: React.component<props<'value>> = "Component"

Thanks in advance!

That’s not possible unless you explicitly type it as an array of React.elements and end up with a slightly more inconvenient API.

1 Like