Infinite Scroll Pagination
Overview
In e-commerce, pagination refers to the process of dividing search results or product listings into multiple pages, which allows users to navigate through the pages of products. It is used to split large sets of products into smaller, more manageable chunks, which can improve the performance of the website and also user experience.
Infinite Scroll Pagination loads the next set of products automatically as the user scrolls to the bottom of the page, eliminating the need for the user to click on next or page numbers. This type of pagination can be helpful for users that want to quickly browse through a large number of products without having to manually click through pages, but it could also lead to lower engagement and higher bounce rates if not implemented well.
Usage
// importing component
import { InfiniteScrollPagination } from "@unbxd-ui/react-search-components";
// import the style for the component
import "@unbxd-ui/react-search-components/styles/infiniteScrollPagination.css";
If the styles import does not work, use the following code to import it:
require.resolve("@unbxd-ui/react-search-components/styles/infiniteScrollPagination.css")
The InfiniteScrollPagination component must be used within the wrapper (in CSR, SSR and Custom Hooks approaches) to ensure that the component and the search functionality work properly.
The InfiniteScrollPagination component must wrap the Products component. For an example of how this component should be rendered, refer to the code in the Live Demo section. This setup ensures that the pre-loader and post-loader are correctly positioned, enabling efficient and smooth functionality.
Live Demo
Props
- A functional component that will be rendered as the pre-loader to render the previous set of products.
- The
LoaderComponent
is highly customisable:- A bare basic component with just a loading text can be used. The following code is the default value of this component:
- You can also choose to add an animated gif or svg as your
LoaderComponent
as follows:
- If you want to keep the product grid flow going, you can create a
LoaderComponent
which is similar to the following example.
- This prop will be used to style the component.
- The value must use a defined structure (the structure can be seen in the following example).
- The keys in the structure must be the same while the values can changed as per the user's choice.
styles={{
wrapper: "pagination-wrapper", // used for the entire pagination component
preLoader: "loader", // used for the pre-loader
postLoader: "loader" // used for the post-loader
}}
Related Hook
To use the Unbxd React Search SDK without the pre-built InfiniteScrollPagination component, add the functionality to your custom component using the usePagination hook. Refer to the documentation for more details.