Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Image with src "/images/logo.png" was detected as the Largest Contentful Paint (LCP)

I am trying to do a project in Next.13 and Typescript. I have created a component named Logo.tsx to render an Image.

"use client";

import Image from "next/image";
import { useRouter } from "next/navigation";

const Logo = () => {
  const router = useRouter();

  return (
    <Image
      alt="logo"
      height="100"
      width="100"
      className="
        hidden
        md:block  
        cursor-pointer
      "
      src="/images/logo.png"
    />
  );
};

export default Logo;

But I am getting this warning.

Image with src "/images/logo.png" was detected as the Largest Contentful Paint (LCP). Please add the "priority" property if this image is above the fold.

I looked into the documentation but could not understand properly. How can remove this error?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have tried adding the prop, priority like this,

    <Image
      priority="true"
      alt="logo"
      height="100"
      width="100"
      className="
        hidden
        md:block  
        cursor-pointer
      "
      src="/images/logo.png"
    />

But I am still getting the warning. And there is a new error in the Eslint,

Type 'string' is not assignable to type 'boolean | undefined'

>Solution :

Refer to the official documentation of next/image.

The TypeScript error you are getting should be a hint, what you are doing wrong. Type 'string' is not assignable to type 'boolean | undefined' That means, that the priority prop expects either a boolean or undefined, but you provided a string.

 <Image
      priority={true} // Change this line
      alt="logo"
      height="100"
      width="100"
      className="
        hidden
        md:block  
        cursor-pointer
      "
      src="/images/logo.png"
    />
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading