rescript-react icon indicating copy to clipboard operation
rescript-react copied to clipboard

Calling `React.forwardRef` with an unlabelled argument gives poor error message

Open sinap-fb opened this issue 4 years ago • 3 comments

Playground: https://rescript-lang.org/try?code=FA3C2D2AmCuA2BTABAIVgFw5AdsgvMgN7DLIACATogIYDGGAdHZOAA66I4anJIbJwNANYpCAJVoNGAM0iUA7jUrRJMgBTqARvBoALADTJqMgJQEAfMV5kAlgHMc8xOpOnSN5AB4tmbDisiACIggFoLSXomAGcMSlscewBfbwB6XyxcC14k9ySQKikmFnZObmB+QRExZHVzfEDeSpMCZEjpWGjENXUAKWjGADkEXR1ERlgcaEQZBMRody90TLwTfBbkVOykoA

Notice that the location of the error is invalid (Line 1, column -1)

sinap-fb avatar Aug 13 '21 19:08 sinap-fb

Please if possible, don't use the React.forwardRef api. Use common props instead, as stated in the docs: https://rescript-lang.org/docs/react/latest/forwarding-refs

We will see how we can improve / deprecate the forwardRef api in the next JSX version

ryyppy avatar Sep 06 '21 11:09 ryyppy

I think if this PR with commit is merged https://github.com/rescript-lang/syntax/pull/586/commits/c59520c59f53554beb843da3410954cf80d70a67, it will point the right location of source code about unlabelled ref in forwardRef.

mununki avatar Jul 05 '22 00:07 mununki

But I agree on the comment from @ryyppy, please don't use the React.forwardRef API if possible 😃

mununki avatar Jul 05 '22 00:07 mununki

Just tested with latest ReScript 10.1 build, and the location is indeed reported correctly now.

cknitt avatar Oct 08 '22 05:10 cknitt