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 trialshubhamvinay
3,741 PointsAt 2.06 why did we update to onClick={() => props.removePlayer(props.index)}?
At 2.06 why did we update to onClick={() => props.removePlayer(props.index)}? and not just onClick={props.removePlayer(props.index)}
1 Answer
Adam Fields
Full Stack JavaScript Techdegree Graduate 37,838 PointsYou have to use an anonymous arrow function to pass an argument to the click handler function, otherwise, you'd actually be calling the function when the code was executed.
props.removePlayer(props.index)
is actually a function call.
() => props.removePlayer(props.index)
is an anonymous function that returns a function.
So the rule of thumb, whenever you need to pass an argument to your handler, wrap it in an arrow function.