App.jsx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
// Build a React.js react-js-pagination Example to Implement Pagination With Controls in JSX Bootstrap import React, { useState } from "react"; import Pagination from "react-js-pagination"; import "bootstrap/dist/css/bootstrap.min.css"; import image1 from "./assets/1.jpeg"; import image2 from "./assets/2.jpeg"; import image3 from "./assets/3.jpeg"; import image4 from "./assets/4.jpeg"; import image5 from "./assets/5.jpeg"; import image6 from "./assets/6.jpeg"; const App = () => { // List of images const images = [image1, image2, image3, image4, image5, image6]; const imagesPerPage = 2; // State for current page const [activePage, setActivePage] = useState(1); // Calculate the images to display for the current page const indexOfLastImage = activePage * imagesPerPage; const indexOfFirstImage = indexOfLastImage - imagesPerPage; const currentImages = images.slice(indexOfFirstImage, indexOfLastImage); // Handle page change const handlePageChange = (pageNumber) => { console.log(`Active page is ${pageNumber}`); setActivePage(pageNumber); }; return ( <div style={{ textAlign: "center", padding: "20px" }}> <h1>Image Pagination Example</h1> <div style={{ display: "flex", justifyContent: "center", gap: "10px" }}> {currentImages.map((image, index) => ( <img key={index} src={image} alt={`Image ${index + 1}`} style={{ width: "200px", height: "150px", borderRadius: "8px" }} /> ))} </div> {/* Pagination Component */} <Pagination activePage={activePage} itemsCountPerPage={imagesPerPage} totalItemsCount={images.length} pageRangeDisplayed={5} onChange={handlePageChange} itemClass="page-item" linkClass="page-link" /> </div> ); }; export default App; |