You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importReact,{useRef,useEffect}from'react';constCanvasComponent=()=>{constcanvasRef=useRef(null);useEffect(()=>{constcanvas=canvasRef.current;constcontext=canvas.getContext('2d');// Draw a simple rectanglecontext.fillStyle='blue';context.fillRect(50,50,200,100);},[]);return<canvasref={canvasRef}width={300}height={200}/>;};exportdefaultCanvasComponent;
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
第一次开发微信小程序。我在React里用canvas习惯的用法是useRef获取canvas对象,大概是这样:
看了一下taro编译出来的代码:
实际运行的结果是 TypeError: canvas.getContext is not a function
不太明白Taro是怎么处理的,是不是不支持react这种写法?
Beta Was this translation helpful? Give feedback.
All reactions