Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda