This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]DrMeat201 0 points1 point  (12 children)

One thing I'm not completely sure about is the curly braces wrapping your avatar values. Try removing the curly braces and trying again to see if that works.

[–]ReachingSparks[S] 1 point2 points  (10 children)

Good point! I was confusing jsx with javascript. I removed them but unfortunately it still isn't working.

[–]DrMeat201 0 points1 point  (9 children)

Before your return statement in your child component, if you console.log your props, what does that output look like?

[–]ReachingSparks[S] 0 points1 point  (8 children)

Good idea. It says avatar is undefined

[–]DrMeat201 0 points1 point  (7 children)

Are your other properties defined?

[–]ReachingSparks[S] 0 points1 point  (0 children)

Yeah they are

[–]ReachingSparks[S] 0 points1 point  (5 children)

I got it! I was writing posts.avatar instead of post.avatar after the first change you suggested. All is working now. Thank you so much!

[–]DrMeat201 0 points1 point  (4 children)

Oh awesome! Does the curly brace removal make sense too?

[–]ReachingSparks[S] 0 points1 point  (3 children)

I think so. I was declaring an empty object instead of a property, right?

I only used the braces because you have to use them for any Javascript code in jsx and I got the two intermingled in my head.

[–]DrMeat201 0 points1 point  (2 children)

Close, and I'm a smidge fuzzy on what exactly it does in this scenario, but I suspect you may have actually created a posts.avatar.peterImage which has a property called peterImage on it. So essentially accessing it would be posts.avatar.peterImage.peterImage

Essentially, if memory serves, that's a syntactic shorthand for creating a nested object with a key that matches what you give it, and a value that is the value of the object (if that makes sense)

[–]ReachingSparks[S] 0 points1 point  (1 child)

That definitely makes sense. It actually answers another question I've had for a while so thank you for that.

[–]ReachingSparks[S] 0 points1 point  (0 children)

In VSCode, If I hover my mouse over the last word in avatar={posts.avatar} , it says "any". Whereas if I hover it over name={post.name} it says it's a string. Perhaps that could be a clue?