lorenzodejong / next-sanity-image

Utility for using responsive images hosted on the Sanity.io CDN with the Next.js image component.
MIT License
149 stars 20 forks source link

Image with src has unused properties assigned. Please remove "width" and "height". #39

Closed ollebergkvist closed 2 years ago

ollebergkvist commented 2 years ago

Warning:

Image with src "https://cdn.sanity.io/images/blabla-667x500.jpg?q=75&fit=clip&auto=format" and "layout='fill'" has unused properties assigned. Please remove "width" and "height".

When using the plugin like this:

{coverImage && imageUrl && (
  <Image {...coverImageProps} alt={alt} layout="fill" objectFit="cover" />
)}
Javi commented 2 years ago

@ollebergkvist How did you fix this? I see the same warning and can't figure it out.

ollebergkvist commented 2 years ago

@Javi

Skip the spread syntax {...coverImageProps}

And do this instead: src={coverImageProps.src} loader={coverImageProps.loader} alt={alt} layout="fill" objectFit="cover"

That worked for me, let me know if it solves the warning for you 👍

Javi commented 2 years ago

Ohh of course, that makes a lot of sense, thank you for the tip!