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

[RFC] Generic JSX transform

$
0
0

Hey,

I have a custom function which should create a jsx element

type options<'props> = {
  name: string,
  render: 'props => Jsx.element,
}

let makeWithProps = options => {
  ...
}
module TestComp = {
  type props = {message: string}

  let make = makeWithProps({
    name: "test-comp",
    render: props => <div> {JSX.string(props.message)} </div>,
  })
}

Now I would like to create components without props like this:

module TestComp2 = {
  let make = makeWithProps({
    name: "test-comp",
    render: () => <div/>,
  })
}

Unfortunately, the compiler complains about the props type (unit). Only records are allowed.

Empty record literal should be annotated or used in a record context.

My workaround is to define a second make function:

type empty = {}

let makeWithoutProps = (options: options<empty>) => {
 ...
}

Which is used like this:

module TestComp3 = {
  let make = makeWithoutProps({
    name: "test-comp",
    render: _ => <div/>,
  })
}

TLDR;
Is it possible to define JSX.elements with unit as props type?


Viewing all articles
Browse latest Browse all 1829

Trending Articles