From abf01d2ade12236851678504a8dfbe1bed71e1de Mon Sep 17 00:00:00 2001 From: Maksym Davydiuk Date: Fri, 8 May 2026 02:07:49 +0300 Subject: [PATCH] Implement Pagination component and App state management --- src/App.tsx | 109 +++++++---------------- src/components/Pagination/Pagination.tsx | 81 ++++++++++++++++- 2 files changed, 113 insertions(+), 77 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 189a990c8..ac10c505d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,17 +1,30 @@ -import React from 'react'; +import React, { useState } from 'react'; import './App.css'; import { getNumbers } from './utils'; +import { Pagination } from './components/Pagination'; -// eslint-disable-next-line @typescript-eslint/no-unused-vars -const items = getNumbers(1, 42).map(n => `Item ${n}`); +const allItems = getNumbers(1, 42).map(n => `Item ${n}`); export const App: React.FC = () => { + const [currentPage, setCurrentPage] = useState(1); + const [perPage, setPerPage] = useState(5); + + const total = allItems.length; + const firstItem = (currentPage - 1) * perPage + 1; + const lastItem = Math.min(currentPage * perPage, total); + const currentItems = allItems.slice(firstItem - 1, lastItem); + + const handlePerPageChange = (e: React.ChangeEvent) => { + setPerPage(Number(e.target.value)); + setCurrentPage(1); + }; + return (

Items with Pagination

- Page 1 (items 1 - 5 of 42) + {`Page ${currentPage} (items ${firstItem} - ${lastItem} of ${total})`}

@@ -19,7 +32,10 @@ export const App: React.FC = () => {