Using the new Next.js Image component with Material UI

7.3k Views Asked by At

In Material UI the components that display images have a parameter for the image. eg:

<Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg" />

In Next.js v10 there is a new Image component that automatically scales images: https://nextjs.org/docs/api-reference/next/image 

Has anyone figured out how to use the new Image component with Material UI?

2

There are 2 best solutions below

1
On

I am able to use it like this and it works well. I hope it will be helpful.

<Avatar className={className}>
  <Image src={src || placeholder} alt={alt} layout="fill" />
</Avatar>
0
On

import image_1 from "/static/images/avatar/1.jpg" //locate image

then just replace

src="/static/images/avatar/1.jpg"

to

src={image_1.src}