I am working on project in ReactJS, I am fetching data from server through API. I did some search filtration, I want to display message if there is no records available? I a
You can check when you get the data back and set an error if no data:
getData(){
const {Item,skip}=this.state;
axios.get(`http://localhost:8001/parties?filter[limit]=${Item}&&filter[skip]=${skip}`)
.then(response=>{
console.log(response.data);
if (!response.data.length) {
this.setState({noData: true})
} else {
this.setState({
data:response.data, noData: false
})
}
})
}
Then in your render function:
render() {
if (this.state.noData) {
return No Data was returned!
;
}
...