reasonrescript

Rescript Capitalised Component


From the Rescript Documentation, it is suggested spread can be used to enable passing a pre-existing list to a component. I am confused what exactly MyComponentis in Rescript as I cannot find a way to initialise a component, which can be done with a function in vanilla React.

<MyComponent>...myChild</MyComponent>

where myChild = list{child1,child2}

After several attempts, the followings do not work:

What I would love is an example of the initialization of the component MyComponent which can be used as a capitalised tag like <MyComponent>...myChild</MyComponent>. Thank you in advance.


Solution

  • module MyComponent = {
     @react.component
     let make = (~children: list<React.element>) => {
       <div> {Belt.List.toArray(children)->React.array} </div>
     }
    }
    

    From Rescript Forum.