Skip to content

Commit 4c89d46

Browse files
Merge pull request #166 from Nosto/addInfiniteScroll
CFE-538 Add info about infinite scroll
2 parents 4f7015e + 8aee608 commit 4c89d46

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

implementing-nosto/implement-search/implement-search-using-code-editor/implementing-search-page.md

+49
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,55 @@ export default () => {
396396
```
397397
{% endcode %}
398398
399+
#### Infinite Scroll
400+
401+
Nosto search-templates library provides a simple out-of-the-box solution to implement infinite scroll functionality. Simply wrapping your product rendering with the `<InfiniteScroll>` component is generally enough.
402+
403+
As the user scrolls the page down, the wrapper will detect it using the `IntersectionObserver`. If it is not supported by the user's browser, a 'load more' button will be shown instead.
404+
405+
{% code title="serp.jsx" %}
406+
```jsx
407+
function Products() {
408+
const products = useAppStateSelector(state => state.response.products)
409+
410+
return (
411+
<>
412+
{products.hits.map((hit, index) => {
413+
return <Product product={hit} key={hit.productId ?? index} />
414+
})}
415+
</>
416+
)
417+
}
418+
419+
function SerpInfiniteScroll() {
420+
return (
421+
<InfiniteScroll>
422+
<Products />
423+
</InfiniteScroll>
424+
)
425+
}
426+
```
427+
{% endcode %}
428+
429+
#### Persistent Search Cache
430+
431+
When using infinite scroll, consider enabling persistent search cache as well. When this feature is enabled, the latest search API response will be automatically cached and stored in the browser's session storage.
432+
433+
This improves the user experience significantly when the user navigates from a product details page back into the search results using the browser's 'back' function. The data necessary to display the products is already available, and the user will see the products immediately, without waiting for them to load again.
434+
435+
This feature is useful for both paginated and infinite scroll, but the benefits are significantly more visible with the latter.
436+
437+
{% code %}
438+
```jsx
439+
import { init } from '@nosto/preact'
440+
441+
init({
442+
...otherFields,
443+
persistentSearchCache: true,
444+
})
445+
```
446+
{% endcode %}
447+
399448
### Product actions
400449
401450
Since the code editor utilizes the Preact framework, it offers significant flexibility in customizing behavior or integrating the search page with existing elements on your site. For instance, you can implement actions such as 'Add to Cart', 'Wishlist', or 'Quick View'.

0 commit comments

Comments
 (0)