Overview
Tienda ETCA implements pagination for the product gallery using React-Bootstrap’s Pagination component. The system displays 5 products per page and includes smooth scrolling to the top of the gallery when changing pages.Implementation
Pagination is implemented in theProductList component at ~/workspace/source/src/components/ProductList.jsx:5-70.
Import
State Management
The pagination state tracks the current page number, starting from 1.
Pagination Logic
The component calculates which products to display based on the current page:Calculation Breakdown
1
Calculate Last Index
1 * 5 = 52
Calculate First Index
5 - 5 = 03
Slice Products Array
productosFiltrados.slice(0, 5) returns items 0-44
Calculate Total Pages
Math.ceil(23 / 5) = 5 pagesPagination UI
The pagination component renders at~/workspace/source/src/components/ProductList.jsx:50-70:
Component Features
Previous Button
Decrements page by 1Disabled on page 1
Page Numbers
Dynamically generated based on total pagesActive page highlighted
Next Button
Increments page by 1Disabled on last page
Smooth Scrolling
When users navigate between pages, the gallery automatically scrolls to the top for better UX:The
isFirstRender check prevents scrolling on initial page load, only scrolling when users actively change pages.Scroll Target
The gallery container is marked with a ref:Integration with Search
Pagination automatically adapts to search results. When users search for products, the pagination recalculates based on filtered results:- All Products (23)
- Search Results (8)
- Search Results (3)
Full Component Code
Complete implementation from~/workspace/source/src/components/ProductList.jsx:7-72:
Customization Options
Change Items Per Page
Reset to First Page on Search
Custom Page Button Styling
Best Practices
Smooth Scroll Enhancement
Smooth Scroll Enhancement
Skip scrolling on initial render to prevent jarring page load:
Dynamic Page Calculation
Dynamic Page Calculation
Always calculate total pages based on filtered results for search compatibility: