Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material-UI CardMedia image not showing

I've applied the styling on to CardMedia but the image still doesn't show

<CardMedia 
    style = {{ height: 0, paddingTop: '56.25%'}}
    image={thread.url}
    title={thread.title}
/>

thread.url is just a link to the image, so I believe it should be working Am I doing it correctly or is there a different way to show the image?

like image 931
Hyokune Avatar asked Oct 17 '25 14:10

Hyokune


2 Answers

If you use create-reac-app it means you probably also use Webpack. Webpack requires you to specify all dpendencies using:

import imageUrl from './image.jpg'

And then you can use it as following:

image={imageUrl}

You can find more information about using Webpack with Create React App here

like image 71
Adam Stepniak Avatar answered Oct 20 '25 03:10

Adam Stepniak


I had the same error, I added style and set height for image and CardMedia started working. Additionally I put my images in public folder but it is working also with external links.

  <CardMedia
    style={{ height: "250px", paddingTop: "2%" }}
    component="img"
    image={"/pancakes.jpg"}
    title="Picture"
    alt="pic"
  />
like image 31
kwny Avatar answered Oct 20 '25 03:10

kwny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!