Skip to content

Stats component does not show the total number of results in a multiple indexes search #6347

Answered by Haroenv
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

stats is only designed for a single index. A solution is using useInstantSearch:

function TotalStats() {
  const { scopedResults, results } = useInstantSearch();

  const totalNbHits = scopedResults.reduce((total, current) => total + current.results.nbHits, 0)

  return <p>found {totalNbHits} in {results.processingTimeMS}ms</p>
}

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@ghost
Comment options

@Haroenv
Comment options

@ghost
Comment options

@Haroenv
Comment options

@ghost
Comment options

Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant