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 trialNorman Lew
Full Stack JavaScript Techdegree Graduate 14,784 PointsWhy are there brackets around this code?
Hi, could you explain why there are brackets around this code?
{this.state.players.map( (player, index) => <Player score={player.score} name={player.name} id={player.id} key={player.id.toString()} index={index} changeScore={this.handleScoreChange} removePlayer={this.handleRemovePlayer} /> )}
2 Answers
HIDAYATULLAH ARGHANDABI
21,058 PointsDear Norman, you have asked a good question in ReactJS when we write HTML and in the HTML div we want to manipulate a place we open two {}
braces. Here you are reading the Player array from the state and sending it to the player component as props.
{
this.state.players.map( (player, index) =>
<Player
score={player.score}
name={player.name}
id={player.id}
key={player.id.toString()}
index={index}
changeScore={this.handleScoreChange}
removePlayer={this.handleRemovePlayer}
/>
)}
Zimri Leijen
11,835 PointsIt's hard to say without context, but it appears to be inside a react component, specifically within JSX.
If that's the case, it's inside curly braces so that when the JSX gets compiled, it knows to interpret that as javascript.
Norman Lew
Full Stack JavaScript Techdegree Graduate 14,784 PointsOk, tx for the reply.
Norman Lew
Full Stack JavaScript Techdegree Graduate 14,784 PointsNorman Lew
Full Stack JavaScript Techdegree Graduate 14,784 PointsOk, tx Hidayatullah.