How to access canvas context in React

后端 未结 6 1150
迷失自我
迷失自我 2021-01-11 11:26

I made a color picker with React and Canvas. Currently the components are rendered in React and canvas is done with vanilla javascript. I\'d like to two to mesh more, so I w

6条回答
  •  天命终不由人
    2021-01-11 11:33

    Here's the React way to remove a canvas from your component:

    const canvas = ReactDOM.findDOMNode(this.refs.canvas); const context = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height);

    As long as you can target the DOM Node the react way, you can pretty much access the Canvas Rendering API.

提交回复
热议问题