This community-built FAQ covers the “Display Information in a Sibling Component” exercise from the lesson “Child Components Update Their Siblings’ props”.
Paths and Courses
This exercise can be found in the following Codecademy content:
Hi,
Still confuse about state and props.
Why do we us this.props.name not this.state.name in Sibling.js???
(The question is due to we us states in Parent.js)
I dont understand how it goes from this.props.onChange(Thinkpiece) from the event handler to triggering the state setter function…
I understand how we’ve passed Thinkpiece through the event object’s name into the Child component:
because through the below code, the const name variable is the drop down selection’s name value.
handleChange(e) {
const name = e.target.value;
this.props.onChange(name);
}
Now…i dont understand the next bit…how does changeName get called with “Thinkpiece” passed as the argument at this stage?
Does it somehow automatically know that this.props.onChange(selectedname) is the same as changeName (selectedname) through the existence of the line <Child onChange={this.changeName} /> ? If so, I don’t see how it can do that?
The onChange property (being the drop down selected name - from the event object) is easy to understand but how does it know to pass that exact same dropdown name into the changeName function? or how does it know to pass it into changeName?