JSFiddle - React, Tailwind, and code Playground
HTML
<a href="#" id="die">DELETE IMG</a>
<input type='file' id="imgInp" />
<div id="canvas">
<img id="uploaded" src="#" alt="your image" />
</div>
JavaScript
function readURL() {
$('#uploaded').attr('src', '').hide();
if (this.files && this.files[0]) {
var reader = new FileReader();
$(reader).load(function(e) {
$('#uploaded').attr('src', e.target.result)
localStorage.setItem('img', e.target.result);
});
reader.readAsDataURL(this.files[0]);
}
}
$('#uploaded').load(function(e) {
$(this).show();
}).hide();
$("#imgInp").change(readURL);
$('#die').click(function() {
localStorage.clear();
window.location.reload();
});