JSFiddle - React, Tailwind, and code Playground
HTML
<button type="button" onclick="pickFile()">Click Me!</button>
JavaScript
function pickFile() {
const input = document.createElement('input');
input.type = 'file';
input.click();
return new Promise((resolve) => {
input.onchange = () => {
console.log('onchange triggered');
if (input.files && input.files.length > 0) {
resolve(input.files[0]);
} else {
resolve(null);
}
};
});
}