JSFiddle - React, Tailwind, and code Playground
HTML
<canvas id="myCanvas" width="300" height="150"></canvas>
<a id="download" download="CanvasDemo.png">Speichern</a>
JavaScript
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "red";
ctx.fillRect(10, 10, 50, 50);
function download() {
var dt = canvas.toDataURL();
this.href = dt;
}
document.getElementById('download').addEventListener('click', download, false);