react-barcode
react-barcode copied to clipboard
How to clear the generated barcode in canvas?
Hi, I have successfully created the canvas. Now, I want to clear this canvas with the click of a button.
<div id="bar_code">
<Barcode renderer="canvas" value={"test"} font="trebuchet ms" height={50} /><br/>
</div>
on click of button, I am trying the code below,
var bar_cnv = document.getElementById('bar_code').firstChild;
var ctx2 = bar_cnv.getContext('2d');
ctx2.clearRect(0, 0, bar_cnv.width, bar_cnv.height);
But the canvas is not getting cleared. Any help will be appreciated.