Luke MarkhamFront End Web Development Techdegree Graduate 17,287 Points
Identifying the callback function
I'm having trouble understanding exactly how this is working.
To my current understanding we:
1) created the function
2) passed it down to
<Player /> via a prop call
3)on clicking the button in
Player we invoke an annoymous function, which then invokes the function
handleRemovedPlayer() that is held in the prop
removePlayer suddenly become a callback function ? isn't it just the prop that represents
removePlayer thought of as a callback because
Player itself is a function ?
David Austin1,217 Points
Hi Luke -
Fellow student here, but I figured that explaining this may help others as well and it helps me to further understand by diving deeper into what is happening. Take a look at the graphic I provided below (credit to Jason Arnold, a Medium author)! After reading further into it, I think you are just coming across a common issue of interpretation. Parent components can communicate to child components with props. But when it is time to have children communicate back, they use the "callback function". The purpose of that is to change a piece of state that is part of the parent component. Remember: props are read-only or "pure" because they don't change their inputs.
Hope I could help!