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

297
Views
Large images don't render as a base64 string in react
import React,{useState,useEffect} from 'react';

function App() {
  const [image,setImage]= useState<File|null>();
 const [preview,setPreview] = useState<string|null>();
  useEffect(()=>{
    if(image){
      const reader = new FileReader();
      reader.onloadend=()=>{
        setPreview(reader.result as string);
        console.log(reader.result);
      }
      reader.readAsDataURL(image);
    }else{
      setPreview(null);
    }  
  },[image])

  return (
    <div className="App">
    <p>plm in grt{preview}</p>

<input type="file" onChange={
  (event:any|null)=>{

    const file:File|null = event?.target.files[0];
    if(file && file.type.substr(0,5)==="image"){
      setImage(file);

    }else{
      setImage(null);
    }
  }
}/>
    </div>
  );
}

export default App;

The base64 string of the image is stored in the "preview" state. When I upload a very small image(500kb), the preview inside the p tag renders. In the case where I upload a 5mb image, the page transforms to white and nothing happens. What would the issue be. If I wait for one minute, the input button renders, but no string shows up on screen. What would be the cause, I'm guessing, the tag renders before the preview stores the whole base64 string?

about 4 years ago · Juan Pablo Isaza
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!