Last active
October 31, 2024 13:50
-
-
Save MoOx/38a846e1414a4f8dec0e7b0e0ff708f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
external link : ReasonReact.reactClass = | |
"default" | |
[@@bs.module "@phenomic/plugin-renderer-react/lib/components/Link"]; | |
let make | |
href::(href: string) | |
style::(style: option ReactDOMRe.Style.t)=? | |
activeStyle::(activeStyle: option ReactDOMRe.Style.t)=? | |
className::(className: option string)=? | |
activeClassName::(activeClassName: option string)=? | |
children => | |
ReasonReact.wrapJsForReason | |
reactClass::link | |
props::{ | |
"href": href, | |
"style": Js.Nullable.from_opt style, | |
"activeStyle": Js.Nullable.from_opt activeStyle, | |
"className": Js.Nullable.from_opt className, | |
"activeClassName": Js.Nullable.from_opt activeClassName | |
} | |
children; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this is an informative post and it is very useful and knowledgeable. I really enjoyed reading this post geometry dash