react canvas clear 1

react canvas clear

var canvas = document.getElementById("myCanvasID");
var context = canvas.getContext('2d');
context.clearRect(0, 0, canvas.width, canvas.height); //clear html5 canvas

Here is what the above code is Doing:
1. It’s creating a variable called canvas and assigning it to the HTML5 canvas element.
2. It’s creating a variable called context and assigning it to the 2D context of the canvas element.
3. It’s clearing the canvas.

Now let’s draw a rectangle on the canvas.

Similar Posts