ml-in-barcelona / jsoo-react

js_of_ocaml bindings for ReactJS. Based on ReasonReact.
https://ml-in-barcelona.github.io/jsoo-react
MIT License
138 stars 19 forks source link

React shows warning when using `maybe` + None #130

Closed jchavarri closed 2 years ago

jchavarri commented 2 years ago

When using a prop with maybe and passing None (e.g. maybe className None), React.js will emit a warning:

Warning: Invalid attribute name: ``
    in div

This happens in ml syntax:

https://github.com/ml-in-barcelona/jsoo-react/blob/d3924adb125a8a7fadb8c2535486127c9b05c1fa/test/test_ml.ml#L704

And Reason syntax:

https://github.com/ml-in-barcelona/jsoo-react/blob/d3924adb125a8a7fadb8c2535486127c9b05c1fa/test/test_reason.re#L1156

I tried using any other string like _ or _unused and in those cases React does not complain 🤔 Another alternative would be to conditionally push to the array.

glennsl commented 2 years ago

Perhaps if we use any "" Js.undefined, React will ignore it?

jchavarri commented 2 years ago

The issue is with the prop name, not the value. I just tried {undefined: undefined} and it works 🤣

https://codesandbox.io/s/spring-framework-enqjl?file=/src/App.js

glennsl commented 2 years ago

I don't get any warning with {'': undefined} either:

https://codesandbox.io/s/compassionate-glade-iep03?file=/src/App.js

jchavarri commented 2 years ago

Ah, you're right. 😕