What kind of issue is this?
Link to repro
https://playground.react.dev/#N4Igzg9grgTgxgUxALhAMygOzgFwJYSYAEMCaAkpgBI4C2ANgKL0K0KY4AUAlEcADrEicQmBwkyRALxEoYBACUynTFHr1uAbkFEJOWMSUBDXADo4pIzgTNW7LvxBwjmAG5GwjgDR8JaIgC+WoIBIAFAA
Repro steps
Playground link
This code:
function refInHtmlElement() {
const ref = useRef(null);
return React.createElement("canvas", { ref });
}
Has this error:
InvalidReact: Ref values (the current property) may not be accessed during render. (https://react.dev/reference/react/useRef) (3:3)
Even though we're using a ref in the way it's meant to be used. If we rewrite it in JSX, the error goes away:
function refInHtmlElement() {
const ref = useRef(null);
return <canvas ref={ref} />;
}
I find this behavior surprising, because I always thought that JSX desugared down to React.createElement anyway....
How often does this bug happen?
Every time
What version of React are you using?
Playground
What version of React Compiler are you using?
Playground
What kind of issue is this?
Link to repro
https://playground.react.dev/#N4Igzg9grgTgxgUxALhAMygOzgFwJYSYAEMCaAkpgBI4C2ANgKL0K0KY4AUAlEcADrEicQmBwkyRALxEoYBACUynTFHr1uAbkFEJOWMSUBDXADo4pIzgTNW7LvxBwjmAG5GwjgDR8JaIgC+WoIBIAFAA
Repro steps
Playground link
This code:
Has this error:
Even though we're using a ref in the way it's meant to be used. If we rewrite it in JSX, the error goes away:
I find this behavior surprising, because I always thought that JSX desugared down to
React.createElementanyway....How often does this bug happen?
Every time
What version of React are you using?
Playground
What version of React Compiler are you using?
Playground