Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Promise stuck on pending Reactjs

Why is my promise still pending. I have modal that has a form submit inside of it. I am trying to return the base64 string of the CSV file. this seems to return what i want but it gets stuck on pending

    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;
    };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you have to await the convertBase64 function when you call it. because the console.log will run before the .then.

and to await the convertBase64 function, you'll have to add the async keyword before defining the convertBase64 function.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!