This is the React InstantSearch v7 documentation.
If you’re upgrading from v6, see the upgrade guide.
If you were using React InstantSearch Hooks,
this v7 documentation applies—just check for necessary changes.
To continue using v6, you can find the archived documentation.
- Infinite hits with a “See more” button at the end of a batch of results. Implement this with InstantSearch’s
InfiniteHits
widget. - Infinite scroll uses a listener on the scroll event (called when users have scrolled to the end of the first batch of results). The following guidance implements such an infinite scroll.
If there are no hits, you should display a message to users and clear filters so they can start over.
Display a list of hits
The first step is to render the results with theuseInfiniteHits
Hook.
React
Track the scroll position
Once you have your results, the next step is to track the scroll position to determine when the rest of the content needs to be loaded (using the Intersection Observer API). Use the API to track when the bottom of the list (the “sentinel” element) enters the viewport. You can reuse the same element across different renders.React
This implementation uses the Intersection Observer API.
To support Internet Explorer 11 you need a polyfill for
IntersectionObserver
. A browser API is used in the example, but you can apply the concepts to any infinite scroll library.React
Retrieve more results
Now that you can track when you reach the bottom of the list, call theshowMore
function inside the observer’s callback.
The Hook exposes whether there are more results to load with isLastPage
, allowing you to conditionally call showMore
.
React
Show more than 1,000 hits
To ensure excellent performance, the default limit for the number of hits you can retrieve for a query is 1,000. If you need to show more than 1,000 hits, you can set a different limit using thepaginationLimitedTo
parameter. The higher you set this limit, the slower your search performance can become.
Increasing the limit doesn’t mean you can go until the end of the hits,
but just that Algolia will go as far as possible in the index to retrieve results in a reasonable time.
Next steps
You now have a good starting point to create an even richer experience with React InstantSearch. Next, you could improve this app by:- Building a native search UI with React Native.
- Checking the API reference to discover more Hooks.