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 trial

React

Why did we call a an anonymous function. For the onClick event to remove an Item?

@4:50 mark, I am kind of confused. In previous videos, for an event handler we didn't use the "()" inside for the "onClick{}" , since we didn't want the function to execute right away.

I understand why an anonymous function was used for this video. Because we want the function to be called when the button is clicked.

I am confused because, is this for every time for an event handler, if we have a callback function that has parameter like onClick{ props.removeItem() } , we will always have to use the "()" inside of the event Handler. So, it will execute?

1 Answer

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

Hi Gremyko Coleman you basically answered your own question, you don't want to invoke the callback function on render, which will happen if you don't wrap an anonymous function around it. You then need the parenthesis syntax as well for the callback function since it takes a parameter for the item in state to be removed.

Oh, I was confused, thank you