我试图设置父类和子类的状态。但是很难想出怎么做。我已经把我认为与手头的问题无关的任何东西都抽象出来了。问题是我
Class Parent extends Component {
constructor(props){
super(props)
this.state = {
foo: "bar"
}
}
coolMethod(n){
this.setState({foo: n})
}
render{
return(
<Child coolmethod={this.coolMethod} />
)
}
}
Class Child extends Component {
constructor(props){
super(props)
}
componentDidMount(){
let that = this;
videojs('my-player', options, function onPlayerReady() {
this.on('end',()=>{
that.props.coolMethod(<whatever string returns as a result of
this method>)
})
})
}
render{
return(
// irrelevant stuff to this question
)
}
}
如果您想了解有关videojs的更多信息:
http://videojs.com/
(虽然这与问题本身无关,但我在孩子的videojs call-in-componentDidMount中引用了它)