Skip to content

Instantly share code, notes, and snippets.

@MoOx

MoOx/link.re

Last active Apr 11, 2018
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@ellascott ellascott commented Apr 11, 2018

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