Get Hits count for each Index hook used inside InstantSearch hook

Hey All, I鈥檓 a bit stuck, and need help, so thanks in advance :pray:
My code is a bit like this repo doc-code-samples/App.js at master 路 algolia/doc-code-samples 路 GitHub, an InstantSearch hook with multiple Index hooks, and the issue is that I want to get the hits count for each Index. I tried using the example provided here useStats() | React InstantSearch Hooks | Algolia but it returns the hits count of InstantSearch hook indexName. Is there a way to scope that useStats example to a specific indexName?

Any pointers much appreciated. Thank you.

Hi Youssef,

A suggestion would be to use the hook useInstantSearch (documentation here). Using this hook, you can access the stats for any Index in an isolated component. Dhaya from our team had this example which shows how to implement this hook:

Also, for useStats (or useHits) to grab the right Index鈥檚 information, it would have to be referenced from within a child component of the Index of interest. By default, if these hooks are not used within an Index it will inherit the main Index from the InstantSearch widget. This is also why you鈥檒l see he removed the first <Index> element in his sandbox above.

Let me know how this works for you! Thanks!