<HitsPerPage> component displays a dropdown to change the number of results displayed per page.
Import
Props
The items to display in the dropdown.
Transform the items before displaying them.
CSS classes to customize the component styling.
Select the number of results per page
<HitsPerPage> component displays a dropdown to change the number of results displayed per page.
import { HitsPerPage } from 'react-instantsearch';
<HitsPerPage
items={[
{ label: '10 hits per page', value: 10 },
{ label: '20 hits per page', value: 20, default: true },
{ label: '50 hits per page', value: 50 },
]}
/>
<HitsPerPage
items={[
{ label: '10', value: 10 },
{ label: '20', value: 20, default: true },
]}
transformItems={(items) =>
items.map((item) => ({
...item,
label: `${item.value} results`,
}))
}
/>
import { InstantSearch, HitsPerPage, Hits } from 'react-instantsearch';
import { liteClient as algoliasearch } from 'algoliasearch/lite';
const searchClient = algoliasearch(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
function App() {
return (
<InstantSearch searchClient={searchClient} indexName="products">
<HitsPerPage
items={[
{ label: '10 hits per page', value: 10 },
{ label: '20 hits per page', value: 20, default: true },
{ label: '50 hits per page', value: 50 },
{ label: '100 hits per page', value: 100 },
]}
/>
<Hits />
</InstantSearch>
);
}