I have two function
- convertToBase64(file) for converting file
- addData(values) for sending the converted file. But result in the second function is always undefined. How to fix this?
async function convertToBase64(file) {
  const fileReader = new FileReader();
  fileReader.onload = () => {
    const srcData = fileReader.result;
    console.log('scrData: ', srcData);     // result is correct
    return srcData;
  };
  fileReader.readAsDataURL(file);
}
async function addData(values) {
  const converted = await convertToBase64(values.file);
  console.log(converted);       // result undefined
  await addDoc(collection(db, 'list'), {
    image: converted,
  });
}
I have tried try...catch, async-await function, but I can't find a solution anyway
 
    