Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jsx and optional arguments #269

Open
jfrolich opened this issue Jun 20, 2020 · 3 comments
Open

Jsx and optional arguments #269

jfrolich opened this issue Jun 20, 2020 · 3 comments

Comments

@jfrolich
Copy link

jfrolich commented Jun 20, 2020

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!

@Drup
Copy link
Member

Drup commented Jun 22, 2020

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.

@jfrolich
Copy link
Author

Yes, id here is just a (bad) example. Allowing optional arguments makes it quite powerful!

@Khady
Copy link
Contributor

Khady commented Feb 8, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants