react passes parameters and values to the function of the parent component props through the child component, and modifies the parent component state, parent component to report an error
this.setState is not a function
Sub-component:
fetch(`${host}/web/news/search_in_channel_with_pub_info?channelId=${channelId}&q=${id}&page=${_this.state.page}&size=${_this.state.size}`,{
method:"GET",
mode:"cors",
}).then(function(response){
_this.setState({
loading:false
})
return response.json().then(function(res){
if(res.content.length===0){
_this.props.handleFetch("false"); //
}
_this.setState({
newsList:res.content,
totalPages:res.totalPages
});
});
:
constructor(props){
super(props);
this.state = {
keyword:this.props.match.params.id,
result:"true",
_isMounted:true
};
this.handleFetch.bind(this)
}
handleFetch(status){
console.log(status) // false
this.setState({
result:status
})
}
<NewsList type="search" id={this.state.keyword} handleFetch={this.handleFetch}/>