JSFiddle - React, Tailwind, and code Playground

HTML

<button onclick="abc()">button</button>
<canvas id="canvas1" height="300" width="300"/>

JavaScript

function abc()
{
alert("msg");
var c=document.getElementById("canvas1");
alert(c);
var ctx= c.getContext('2d');
alert(ctx);
ctx.beginPath();
ctx.moveTo(0,0);
ctx.lineTo(300,150);
ctx.stroke();
}