Dealing with Pagination:
const CarsSection = () => {
const itemsPerPage = 8;
const [itemOffset, setItemOffset] = useState(0);
const endOffset = itemOffset + itemsPerPage;
const currentItems = carsData.slice(itemOffset, endOffset);
const pageCount = Math.ceil(carsData.length / itemsPerPage);
const handlePageClick = (event) => {
const newOffset = (event.selected * itemsPerPage) % carsData.length;
setItemOffset(newOffset);
};
return (
<>
<PaginationTop>
<ReactPaginate
nextLabel=">"
onPageChange={handlePageClick}
pageRangeDisplayed={3}
marginPagesDisplayed={2}
pageCount={pageCount}
previousLabel="<"
pageClassName="page-item"
pageLinkClassName="page-link"
previousClassName="page-item"
previousLinkClassName="page-link"
nextClassName="page-item"
nextLinkClassName="page-link"
breakLabel="..."
breakClassName="page-item"
breakLinkClassName="page-link"
containerClassName="pagination"
activeClassName="active"
renderOnZeroPageCount={null}
/>
</PaginationTop>
<CarsContainer>
<Items currentItems={currentItems} />
</CarsContainer>
//Same <ReactPaginate /> (code is too big couldn't put it down)//
</>
);
};
export default CarsSection;
Currently implementing two separate paginators at top and bottom. Issue arises when clicking on bottom paginator doesn't update the state for the top paginator.
Attempted using forcePage={itemOffset}, but results were not as expected...