Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjlampstack
23,932 PointsUsing Explicit Return for this lesson
My code works fine when using an explicit return like the instructor, but for my personal preferences I like seeing the () parenthesis and {} curly braces. But for some reason my UI won't render with explicit return.
Can anyone tell me how to use explicit return for this? Thanks in Advance!
My Explicit Return (Doesn't Work)
{ props.initialPlayers.map( ( player ) => {
<Player
name={ player.name }
score={ player.score}
/>
}) }
Instructors Implicit Return (Works)
{ props.initialPlayers.map( player =>
<Player
name={ player.name }
score={ player.score}
/>
) }
1 Answer
jlampstack
23,932 PointsNevermind, I finally figured it out. I never realized you need to use return keyword and a second set of () parenthesis.
This works
{ props.initialPlayers.map( ( player ) => {
return (
<Player
name={ player.name }
score={ player.score}
/>
);
}) }
Looking at this now it doesn't look as nice and I see why Guil used an implicit return. It looks much nicer.
ankushdharkar
7,530 Pointsankushdharkar
7,530 PointsYes. You're right. Good find You can learn more about the brevity of this fat arrow syntax here: https://teamtreehouse.com/library/introducing-arrow-function-syntax