JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<button onclick="importData()">Upload</button>
</body>
JavaScript
function importData() {
let input = document.createElement('input');
input.type = 'file';
input.id = 'restoreBtn';
input.onchange = _ => {
// you can use this method to get file and perform respective operations
let fReader = new FileReader();
fReader.readAsText(input.files[0]);
fReader.onloadend = function(event){
let msg = {payload:event.target.result, name: input.files[0].name}
alert(JSON.stringify(msg))
}
}
input.click();
}