How to know if hits are currently loading?

Hello,

We’re using connectInfiniteHits to display all of the hits in our app, and we would like to be able to differentiate between

(1) a response from Algolia has been received, and there are no hits
(2) a response from Algolia has not yet been received

currently these two cases look the same inside our results component, as the props received are the same, namely hits = [].

Either adding another prop to determine whether results are currently loading or settings hits = null until a response has been received both seem like decent approaches to this problem, but I think this has to be changed within the library itself.

Or is there perhaps another way of distinguishing between these two states that I am not aware of?

Thank you in advance!

1 Like

Hi @bjorn,

You can see if the search is in progress by looking at a “searching” variable. It’s what we call “Conditional Display”, see: https://community.algolia.com/react-instantsearch/guide/Conditional_display.html#displaying-content-when-theres-no-results

You might also want to have a look at this: https://github.com/algolia/react-instantsearch/issues/87

Please note that in the future we might provide an intermediary API that let you handle this kind of use case without the need of using createConnector.

1 Like

Thank you very much! This is just what I needed. :slight_smile: