I am mapping an array of objects to display a set of MUI cards with the "cardMedia" component. The images show well in my localhost but when I deployed to netlify, the images were broken.
This is the mapped code
{
AboutUs.map(info=>(
<Card key={info.id} className='shadow-none bg-transparent'>
<CardMedia
component="img"
image={info.imgUrl}
className='w-16 h-auto ml-3'
/>
<CardContent>
<p className='text-2xl font-bold mr-2 my-3.5'>{info.title}</p>
<p className='text-base'>{info.information}</p>
</CardContent>
</Card>
))
}
Below is the exported Data;
export const AboutUs = [
{
id:1,
title:"Property Insurance",
information:"We offer our customer property protection of liability coverage and insurance for their better life.",
imgUrl:"./src/assets/icons-large/property_insurance.svg"
}
]
2
Answers
Apparently this issue was because I was using React Vite, I solved the issue by placing my entire assets folder in my public folder and since it was a root path I called it from the array like this;
Now the page renders without issues in Netlify
as you addressed the
imgUrl
in your localhost directory, you’ve to require the image in order to be bundled with your app so it can be displayed in your VPS.