Reason-react generic component without functor


#1

Hi,

I am starting with reasonml and I am creating a bindings for a library that one of the props is generic and next it have an other prop that it is a functions that get the value of the other prop. I know i can do this with functors but i want to know if it is posible to use a syntax like this:

Implementation

let make('data) = ....

use

<MyComponent(string)
 prop1="Hi"
 prop2={data => data}
/>

If i try to do that i get a syntax error in the implementation, i only want to know if it is possible or something similar or i have to make a functor.

Thank you.


#2

Try it

Implementation

[@react.component]
let make = (~prop1: string, ~prop2: 'data => 'data) => {
    /* ... */
};

use

<MyComponent(string)
 prop1="Hi"
 prop2={data => data}
/>
***

#3

What about to use the same type in more than one prop?

In this case both props depends on the same type, if i set int, It will need prop1 as int and the function of prop2 is executed as argument with int.

I don’t know if It is possible without functor.

[@react.component]
let make = (~prop1: 'data, ~prop2: 'data => 'data) => {
    /* ... */
};

The problem in this example is that this two types can be diferent, i need something global to have the same type.