reasonml / reason-react

Reason bindings for ReactJS
https://reasonml.github.io/reason-react/
MIT License
3.25k stars 347 forks source link

Very misleading error message if you misuse [@react.component] #843

Open Josef-Thorne-A opened 2 months ago

Josef-Thorne-A commented 2 months ago

If you put [@reason.component] in the wrong location it will give a very confusing and uninformative error. This took me a couple hours to track down properly:

Example of problematic code:

[@react.component]`
let (pageState,setPageState) = React.useState(_ => testState);

let make { ...}

For me at least in an error message in the associated dune file was given, nowhere near where the issue was -- nor obviously related to incorrect ppx directives:

7 |  (preprocess (pps melange.ppx reason-react-ppx)))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Fatal error: exception Invalid_argument("react.component calls cannot be destructured."