Skip to content

Instantly share code, notes, and snippets.

@MoOx
Last active April 11, 2018 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MoOx/38a846e1414a4f8dec0e7b0e0ff708f6 to your computer and use it in GitHub Desktop.
Save MoOx/38a846e1414a4f8dec0e7b0e0ff708f6 to your computer and use it in GitHub Desktop.
let component = ReasonReact.statelessComponent "BodyRenderer";
let make body::(body: PhenomicContent.jsBody) _children => {
let rec renderChild child =>
switch child {
| PhenomicContent.String string => ReasonReact.stringToElement string
| PhenomicContent.Element tag originalProps reasonChildren =>
let props = ReactDOMRe.objToDOMProps originalProps;
switch tag {
| "a" =>
<Link href=[%bs.raw {| child[1].href |}]>
(
[%bs.raw {|child[2]|}] |> Array.of_list |> ReasonReact.arrayToElement
)
</Link>
/*
Error: This expression has type
style::option ReactDOMRe.Style.t =>
activeStyle::option ReactDOMRe.Style.t =>
className::option string =>
activeClassName::option string =>
ReasonReact.component
ReasonReact.stateless ReasonReact.noRetainedProps
but an expression was expected of type
ReasonReact.component 'a 'b = ReasonReact.componentSpec 'a 'a 'b 'b
*/
| _ =>
ReactDOMRe.createElement
tag
::props
[|
ReasonReact.arrayToElement (
Array.of_list (List.map renderChild reasonChildren)
)
|]
}
| PhenomicContent.Empty => ReasonReact.nullElement
};
{
...component,
render: fun _self => {
let tree = PhenomicContent.jsTreeToReason body;
<div> (renderChild tree) </div>
}
}
};
@ellascott
Copy link

I think this is an informative post and it is very useful and knowledgeable. I really enjoyed reading this post geometry dash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment