everyone. I'm fairly new to React Js, and I got stuck while trying to render images from an array. My code is :
import { home } from "../homeObj";
const Logos = ({ title, img, img2, img3, key }) => {
return (
<>
<div className={styles.anaShif} key={key}>
<h2 className={styles.h2}> {title} </h2>
<div className={styles.logos}>
<img
id={img.id}
src={img}
alt={img.alt}
className={styles.img}
srcSet={`${img2} 2x,
${img3} 3x`}
/>
</div>
</div>
</>
);
};
function Trusted() {
const logoComponent = home.map((_objects, i, id) => {
if (home[i].id === "logos") {
return (
<>
<Logos
key={i}
id={id}
title={home[i].title}
img={home[i].logos[i].src}
/>
</>
);
}
});
return (
<>{logoComponent}</>
);
}
export default Trusted;
and { home } :
export const home = [
{
id: "logos",
title: "Welcome to",
logos: [
{
id: 1,
alt: "car",
src: require("./logo_06.png"),
src2: require("./[email protected]"),
src3: require("./[email protected]"),
},
{
id: 2,
alt: "red-car",
src: require("./logo_07.png"),
src2: require("./[email protected]"),
src3: require("./[email protected]"),
},
],
]
What happens is that I can only display an image of the 2nd element of logos array, it's like React Js completely skips 1st element(id, img.src, alt).
What I want to do is to be able to display both images at the same time and also add elements dynamically, when a new element gets added to {home}, it should display without hardcoding.
Any help would be greatly appreciated.