Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Flow-like render types?

$
0
0

hmm I actually tried and it’s pretty cumbersome to redefine the return type of a JSX element in practice because mixing the return types of those JSX elements between custom and regular Jsx.element becomes a pain, I’d recommend to just use a regular a function here see playground:

module Header = {
  type t
  external fromElement: React.element => t = "%identity"
  external toElement: t => React.element = "%identity"
}

let s = React.string

module H1 = {
  let make = (~text: string) => {
    {<h1> {s(text)} </h1>}->Header.fromElement
  }
}

module Layout = {
  @react.component
  let make = (~children: Header.t) => <div> {children->Header.toElement} </div>
}

@react.component
let make = () => {
  <Layout> {H1.make(~text="hello")} </Layout>
}

There’s some work ongoing around making React components abstract, it could potentially allow this I think.


Viewing all articles
Browse latest Browse all 2592

Trending Articles