Jsx and optional arguments
If I do the following
<h1 ?id>...contents</h1>
I get the warning of "unexpected optional jsx attribute" while id is an optional argument on h1. Would be great to have this supported!
Hmm, that's interesting. I didn't remember this syntax being accepted by JSX. id isn't really an "optional argument" in the usual meaning of the word. We could expand the code to make it work though, that would be a nice feature.
Yes, id here is just a (bad) example. Allowing optional arguments makes it quite powerful!
Faced a similar problem today. I was expecting this kind of code to work
module Demo = {
let createElement = (~opt=?, ()) => {
switch (opt) {
| None => ()
| Some(_) => ()
};
};
};
let opt = None
let () = <Demo />
let () = <Demo ?opt />
Apparently it works fine with the reactjs jsx https://reasonml.github.io/en/try?rrjsx=true&reason=NoAQRgzgdAxg9gOwGYEsDmACA3gKwgDwC4MBmAXwF0BuAKBoFs4ATAVwBsBTDAcQCcOOAFxQJMAXmw0MGUPwCGMQbDj0ADog4JBFKRk6CM9OQGsuEgBQA-JHDhiARACZ7ASgxiAfJOnSAPGBZBQUQvLAAlDgUlCEFeETRzGzgXMgxfAHoAoJDdMlo8un0MJPcMADkNWgiogBEAeQBZCKh+BCYOXgAVOABRTnpNQQB1FEEACwBJJnNfPgFhUQwAfiT0jwAaDHtVfgA3FA4Ad1cqIA