0

I have a simple file opener:

        <input type="file" onChange={async (e) => {
            let importedRows = await importTSVFile(e)
            console.log(importedRows)

        }} />

My importTSVFile function looks like this:

// CLIENT SIDE FUNCTIONS

export const importTSVFile = async (e) => {
    e.preventDefault();
    const reader = new FileReader();
    reader.onload = async (e) => {
        //extracting the rows here
        let newRows = //....
        return newRows
    };

    await reader.readAsText(e.target.files[0]);
};

However, I think I am getting something wrong with async/await here. The console.log, which attempts to log the return value of importTSVFile (importedRows), is undefined or a promise. What is it that I am misunderstanding here?

antonwilhelm
  • 5,768
  • 4
  • 19
  • 45

0 Answers0