Being able to directly write a component like this is great for some cases, but usually I’d rather stay with @react.component so that the compiler can infer the prop types and I do not have to spell them out myself.
So in this example I’d stay with
module Component = {
@react.component
let make = (~x) => React.string(x)
}
But in future, we might be able to go without @react.component entirely.
How could this work without having to spell out the prop types explicitly every time?
So you still need to write the props explicitly and just allow them to be polymorphic? That’s a lot less comfortable than just writing @react.component
module Component = {
type props<'x> = {x:'x}
let make = props => React.string(props.x)
}
Whenever I look this implementation, the expressivity looks quite improved to me, even without @react.component attribute. The empty record type and value would make the expressivity better.
Thanks! Yes, my code for the context provider is like this, and changing to record fixes the problem.
About the new handling of key:
In JSX v3, this used to be zero cost, the key was just included in the props object literal.
In JSX v4 classic mode, there are now helper functions used that will cause additional overhead:
function createElementWithKey(component, props, key) {
return React.createElement(component, Jsx.addKeyProp(props, key));
}
function createElementVariadicWithKey(component, props, elements, key) {
return Caml_splice_call.spliceApply(React.createElement, [
component,
Jsx.addKeyProp(props, key),
elements
]);
}
This does not seem like an improvement over JSX3. At least I think we should inline these calls, and use Js.Obj.assign directly or define Jsx.addKeyProp as an external based on Object.assign. (But the Object.assign itself is already overhead.)
In JSX v4 automatic mode, this problem does not exist, as the key is passed as a separate arg to the jsx function).
I meant not just inlining the Object.assign, but couldn’t we also get rid of the helper function createElementWithKey by having the PPX directly generate