Check out example codes for "how to convert a html canvas into a png file". It will help you in understanding the concepts better.

Code Example 1

let canvas = document.getElementById("mycanvas");
let img = canvas.toDataURL("image/png");
document.write('<img src="'+img+'"/>');

Learn ReactJs, React Native from akashmittal.com