classCanvasextendsReact.Component{constructor(...args){super(...args);this.state={x: 100,t: Date.now()};this.animate();}animate(){requestAnimationFrame(()=>{constd=Math.PI*(Date.now()-this.state.t)/1000;constx=200+100*Math.sin(d);this.setState({ x });this.animate();});}render(){constx=this.state.x;return<Rectanglex={x}y={100}width={100}height={100}color="red"/>;}}