rescript-react icon indicating copy to clipboard operation
rescript-react copied to clipboard

Have a way to create components with props = domProps

Open ryyppy opened this issue 4 years ago • 2 comments

There are use-cases where you want to create components that replicate native dom elements, such as <button>, <a>, etc.

For that, you'd need something like ReactDOM.domProps, but as a @obj makeProps binding.

Maybe this issue is not relevant when we finally ship JSX v4, but would still be great to have a streamlined solution for current JSX v3 users.

Related discussions:

  • https://forum.rescript-lang.org/t/return-component-from-hook-bind-to-component-with-ref-to-div/2383/8

ryyppy avatar Sep 14 '21 10:09 ryyppy

Hey @ryyppy

Jumping into this issue just to propose a solution

A possible solution to this is to have a decorator that generates the list of props the same way as makeProps does. In styled-ppx I need to exactly do that, so all HTML element's props remain available from the outside: https://github.com/davesnx/styled-ppx/blob/main/packages/ppx/src/makeProps.re.

I'm not saying that should be fixed, just proposing a solution!

davesnx avatar Dec 05 '21 23:12 davesnx

@ryyppy This is not an issue in JSX 4 anymore, right?

So with JSX 4 around the corner, can this be closed?

cknitt avatar Sep 26 '22 15:09 cknitt

@ryyppy Just tested, this is indeed possible with JSX 4:

module MyDiv = {
  type props = JsxDOM.domProps

  let make = props => <div {...props} />
}

cknitt avatar Oct 07 '22 17:10 cknitt