JSFiddle - React, Tailwind, and code Playground
JavaScript
function getFileContent(fileName) {
return new Promise(resolve => {
alert("Opening the file...")
// get the file content here with $.get()
setTimeout(async () => {
resolve(`Content of a file ${fileName}`)
}, 1000)
})
}
async function fetchFile() {
alert("Fetching file contents...")
const content = await getFileContent("foo.txt")
alert(`Fetched: ${content}`)
}
fetchFile()