React : How to Show Message if there is no records

前端 未结 5 1080
耶瑟儿~
耶瑟儿~ 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:34

    You could check for the data before render the component and return another component if you don't have any. Using expressions such This example ‘’’ { doIHaveData ? < Component1 /> : < Component2 />} ‘’’

    Where Component1 has your functionality and Component2 return a message or a spinner loader whatever you want .

    I hope it helps!

    When you are checking for the empty array you could check for array type and length. I would personally do something like

     {Array.isArray(array) && array.length === 0 ?  : } 
    

提交回复
热议问题