Instantsearch stats

Hi there,

I am currently looking for a solution to get the statistics from Instantsearch, instead of simply displaying them using the Stats widget. I would like to be able to access the data directly as searches happen. As an example, I am imagining something like this:

   onSearchStateChange={(result) => this._setSearch(result.query)}
   onStatsChange={(stats) => doStuff(stats)}

Does anyone know of a solution for this?

Thank you,

Is there a reason why you would prefer an event rather than getting the props? If you don’t want to use the stats widget, you can also do a custom connector


My goal is to simply get the data, so if I can do that via props then that would work well. I am looking into the connector now.

1 Like

Could you perhaps show a working example of the connectStats connector that is able to capture the hits passed down via props? This is what I am currently trying without any results:

    const myStats = ({nbHits, processingTimeMS}) => {
      console.log(nbHits, processingTimeMS)


With connect stats, I am able to return jsx, but that is all. I have not been able to simply capture the data as of yet.

Does anyone have a solution for this? My goal is to be able to capture the total number of search results as the search as the search takes place.

Here’s an example using connectStats that is working:

1 Like