react read multiple files with filereader

Solutions on MaxInterview for react read multiple files with filereader by the best coders in the world

showing results for - "react read multiple files with filereader"
Valerio
30 Jun 2020
1handleFileChosen = async (file) => {
2  return new Promise((resolve, reject) => {
3    let fileReader = new FileReader();
4    fileReader.onload = () => {
5      resolve(fileReader.result);
6    };
7    fileReader.onerror = reject;
8    fileReader.readAsText(file);
9  });
10}
11
12
13readAllFiles = async (AllFiles) => {
14  const results = await Promise.all(AllFiles.map(async (file) => {
15    const fileContents = await handleFileChosen(file);
16    return fileContents;
17  }));
18  console.log(results);
19  return results;
20}
21