React : How to Show Message if there is no records

前端 未结 5 1077
耶瑟儿~
耶瑟儿~ 2021-01-16 18:35

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

5条回答
  •  星月不相逢
    2021-01-16 19:21

    You can make use of conditional rendering!

    render(){
    const filteredItems = this.getDataItems(this.state.filtered);
    const dataItems = this.getDataItems(this.state.data);
    
    if(dataItems){
    return(
     
    Your Message
    ) } else{ //Your normal code } }

提交回复
热议问题