JSFiddle - React, Tailwind, and code Playground
HTML
<canvas id="canvas"></canvas>
JavaScript
function get_canvas() {
return $('#canvas')[0];
}
function get_context() {
return get_canvas().getContext('2d');
}
function clear_canvas() {
var canvas, context;
canvas = get_canvas();
context = get_context();
context.save();
context.setTransform(1, 0, 0, 1, 0, 0);
context.clearRect(0, 0, canvas.width, canvas.height);
context.restore();
}
function draw_rectange() {
var context = get_context();
context.fillStyle = 'black';
context.fillRect(0, 0, 100, 100);
}
$(function() {
setInterval(function() {
console.log('called');
clear_canvas();
draw_rectange();
}, 1000);
});