signal r in react how to know if there's no data coming from sockets?

Viewed 32

the problem I'm facing is I'm creating a connection to my hub and then invoking some URLs to that connection and all of the responses are arrays, the problem is that the sockets don't return an empty array for example this is my code.

connection.on(MarketIRT, (items) => {
     setIRTMarket(items)
});

So if there are any items in that socket there is no problem, the problem only occurs when there's no data in them so basically when items = [] . how should I know when there are no items in there so I can show a placeholder or even a loader?

1 Answers
connection.on(MarketIRT, (items) => {
    // check if items is actually array
    // and if it's empty
    if (Array.isArray(items) && items)
      setIRTMarket([])
    else 
      setIRTMarket(items)
});
Related