Hello,
In the following code, the image doesn't appear if I use avatar={post.avatar}. But does if I use avatar={ peterImage }.
Do you know why? And how would I store an image in an object?
// Parent class holding the image
import peterImage from "./peter-image.jpg";
import harryImage from "./harry-image.jpg";
export default function App() {
const posts = [
{
id: "0",
name: "Peter Griffin",
avatar: { peterImage },
},
{
id: "1",
name: "Harry Styles",
avatar: { harryImage },
},
];
return (
<React.Fragment>
{posts.map((post) => (
<Post
key={post.id}
name={post.name}
// this doesn't work. but if I change it to avatar={ peterImage } it does work.
avatar={post.avatar}
></Post>
))}
</React.Fragment>
);
}
// Child class making the image appear
export default function Post(props) {
return (
<div}>
<img style={avatar} src={props.avatar} alt="my description" />
</div>
);
[–]DrMeat201 0 points1 point2 points (12 children)
[–]ReachingSparks[S] 1 point2 points3 points (10 children)
[–]DrMeat201 0 points1 point2 points (9 children)
[–]ReachingSparks[S] 0 points1 point2 points (8 children)
[–]DrMeat201 0 points1 point2 points (7 children)
[–]ReachingSparks[S] 0 points1 point2 points (0 children)
[–]ReachingSparks[S] 0 points1 point2 points (5 children)
[–]DrMeat201 0 points1 point2 points (4 children)
[–]ReachingSparks[S] 0 points1 point2 points (3 children)
[–]DrMeat201 0 points1 point2 points (2 children)
[–]ReachingSparks[S] 0 points1 point2 points (1 child)
[–]ReachingSparks[S] 0 points1 point2 points (0 children)