function getElement(){
const el = document.createElement('canvas');
el.drawImage(...);
...
return el;
}
function App() {
const canvasRef = React.useRef(null);
React.useEffect(()=>{
const canvasEl = getElement(); // It returns HTMLCanvasElement
document.body.append(canvasEl); // It works but it isn't my desired
canvasRef.current = canvasEl; // It doesn't work
}, []);
return (
<div><canvas ref={canvasRef} /></div>
)
}
It is simplified code so my actual code is much more complicated.
How can I inject HTMLCanvasElement into ref?
getElement()using ref.getElement()inside the div?