problem description
the environmental background of the problems and what methods you have tried
have you tried the arrow function, but it still doesn"t work
related codes
/ / Please paste the code text below (do not replace the code with pictures)
parent component
handleSubmitComment(a) {
// console.log(a)
this.state.lists.push(a)
this.setState({
lists: this.state.lists
})
}
<ComInput>
onSubmit = {this.handleSubmitComment.bind(this)}
</ComInput>
subcomponents
handleSubmit(){
console.log(this)
if(this.props.children[1]){
const {username,content} = this.state
this.props.children[1]({username,content})
}
this.setState({
content:"",
username:""
})
}
<button onClick={this.handleSubmit.bind(this)}></button>
what result do you expect? What is the error message actually seen?
shouldn"t it be this.props.onSubmit ()
to get it? why is there an array?