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

216
Views
Get Image sizes from a url in React/Next.js

I'm trying to get the image sizes from a URL in my Next.js app so I can use the NextJs Image component. I'm fetching the images from a Headless CMS that only returns the urlm so I was trying to do something like:

const BuilderImage = ({ src, alt }) => {
  const [imageDimensions, setImageDimensions] = useState({ width: 1024, height: 500 });
  
  const img = new Image();

  useEffect(() => {
    img.src = src;

    img.onload = () => {
      setImageDimensions({
        height: img.height,
        width: img.width
      });
    };
  }, []);

  return (
    <Image
      src={src}
      width={imageDimensions.width}
      height={imageDimensions.height}
      alt={alt}
      objectFit="cover"
    />
  );
};

But it isn't working. My error:

TypeError: Cannot destructure property 'src' of '_param' as it is undefined.

Does anybody knows what's going on? thanks

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!