How can I resolve the pending status of my promise? I have a modal with a form submit in it, where I am trying to retrieve the base64 string of a CSV file. While my code seems to be returning the desired result, it remains stuck in a pending state.
const convertBase64 = (file: any) => {
return new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.readAsDataURL(file);
fileReader.onload = () => {
resolve(fileReader.result);
};
fileReader.onerror = (error) => {
reject(error);
};
});
};
const handleFileRead = (file: File) : string | null => {
const base64 = convertBase64(file).then(
ret => {
return ret;
},
err => {
console.log(err);
return null;
});
console.log("handleFileRead after conversion:", base64);
return null;
};