<Stats> component displays statistics about the current search results, such as the number of hits and processing time.
Import
Props
Customize the text to display.
CSS classes to customize the component styling.
Learn more about Mintlify
Enter your email to receive updates about new features and product releases.
Display search statistics
<Stats> component displays statistics about the current search results, such as the number of hits and processing time.
import { Stats } from 'react-instantsearch';
<Stats
translations={{
rootElementText({ nbHits, processingTimeMS, nbSortedHits, areHitsSorted }) {
return areHitsSorted && nbHits !== nbSortedHits
? `${nbSortedHits.toLocaleString()} relevant results sorted out of ${nbHits.toLocaleString()} in ${processingTimeMS.toLocaleString()}ms`
: `${nbHits.toLocaleString()} results found in ${processingTimeMS.toLocaleString()}ms`;
},
}}
/>
import { InstantSearch, SearchBox, Stats, Hits } from 'react-instantsearch';
import { liteClient as algoliasearch } from 'algoliasearch/lite';
const searchClient = algoliasearch(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
function App() {
return (
<InstantSearch searchClient={searchClient} indexName="products">
<SearchBox />
<Stats />
<Hits />
</InstantSearch>
);
}
function App() {
return (
<InstantSearch searchClient={searchClient} indexName="products">
<Stats
translations={{
rootElementText({ nbHits, processingTimeMS }) {
return `${nbHits} product${nbHits !== 1 ? 's' : ''} found (${processingTimeMS}ms)`;
},
}}
/>
<Hits />
</InstantSearch>
);
}
// Example output with sorted results:
// "42 relevant results sorted out of 1,234 found in 23ms"
function App() {
return (
<InstantSearch searchClient={searchClient} indexName="products">
<SearchBox />
<Stats />
<Hits />
</InstantSearch>
);
}