I just saw this in the ReScript React docs. What are the reasons for this choice ? Record types seem easier to work with, can use the spread syntax, facilitate HOC and are the common way to work in React. And why is @react.component
needed?
Can anyone explain?
In ReactJS, props are usually described as a single props record. In ReScript, we use labeled arguments to define our props parameters instead.
Some guesses:
- optional parameters (optional fields in records weren’t able a few versions ago)
- performance (just pass parameters instead of creating objects, but probably the compiled code will be the same)
Btw.: if you create a make function with a props record as parameter, you don’t need @react.component or @jsx.component
I use it only for components without props.
Or maybe your question is React-specific.
In JSX v4, you can use record types for sharing.
But still, labeled arguments can provide better ergonomics. It allows for co-locating type definitions and inference without having to duplicate declarations.
This is a feature that TypeScript people are really envious of, and is also a proposal for the Component DSL that Flow recently added.
We’re already ahead of the curve
9 Likes