11

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?

Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57
terchris
  • 545
  • 6
  • 16

2 Answers2

12

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>
  • Please use the `fill` prop instead of `layout="fill"` from now on. The layout prop is deprecated. – SpBills Feb 14 '23 at 19:56
0

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}