react-hooksalgoliainstantsearch.js

instanceSearch to instenceSearch react Hook


I am planing to move from react instanceSearch to instenceSearch react Hook. React instanceSearch provide allSearchResults attribute. How can I get allSearchResults for Multi indices in InstenceSearch react Hook

In instanceSearch Algolia doc had this

Multi indices#

If you’re using the Index widget with conditional rendering, access the searchResults and the results of all indices (with allSearchResults).

However, this part is missing in the React InstantSearch Hooks documentation. The support team suggests using the "useInstantSearch()" hook, but I couldn't find a way to use it when performing a multi-index search.

My main requirement is to change the order of the indices in the UI based on the results count, and the first hit of all indices should have fullyHighlighted. I'm looking for a solution to prioritize those indices.


Solution

  • Solution is simple

    const { scopedResults } = useInstantSearch();
    

    Then you can find the index by name

    scopedResults.find((item) => item.indexId === indexId)