I am trying to draw rectangle with one diagonal line using canvas and script. But, unfortunately rectangle alone is getting displayed in my browser. It looks like the script is not executed.
Code:
import React, { Component } from 'react';
import '../App.css';
class Graphics extends Component{
render(){
return(
<div id="canvas">
Draw a diagonal Line in Rectangular
<canvas id="myCanvas" className="canvas-style" width="200" height="100">
</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.moveTo(0,0);
ctx.lineTo(200,100);
ctx.stroke();
</script>
</div>
);
}
}
export default Graphics;