Answer the question
In order to leave comments, you need to log in
How to manage the state of a child component?
Hello, I started to do a small project and a question arose. I don't know how to control the state of the child component from the parent. I have a click handler in the parent and it needs to change the state of the child component. How to implement it?
Answer the question
In order to leave comments, you need to log in
does that mean?
onClick = e => {
this.setState({daughter: 21}) // тут меняем стейт в родителе
}
....
<Something onClick={this.onClick} /> // тут "клик в родителя"
<DaughterComponent someValue={this.state.daughter} /> // это будет доступно в компоненте как props.someValue, и там уже рендерить как надо
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question