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

Even more JSX customization

$
0
0

FYI:

In my current custom implementation, generic components doesn’t work.
Following code would throw an error.

// Select.res
type props<'a> = {
  options: array<'a>,
  getOptionId: 'a => string,
  getOptionLabel: 'a => string,
}

let make = M.componentP(_ => {
  view: vnode => {
    <ul>
    </ul>
  },
})
// App.res
<Select ... />

My solution are module functions (haha, you can’t write “f u n c t o r s”). But this nees a lot boilerplate code.

// Select.res
module type Props = {
  type item
}

module Make = (Props: Props) => {
  type props = {
    options: array<Props.item>,
    getOptionId: Props.item => string,
    getOptionLabel: Props.item => string,
  }

  let make = M.componentP(_ => {
    view: vnode => {
      <ul>
      </ul>
    },
  })
}
// App.res
module PetSelect = Select.Make({
  type item = pet
})

<PetSelect ... />

Viewing all articles
Browse latest Browse all 2592

Trending Articles