From a9cecd0ae69d304a57c8403cd195008b0361bd99 Mon Sep 17 00:00:00 2001 From: Yuliia Voroniuk Date: Thu, 15 Jan 2026 15:58:49 +0200 Subject: [PATCH 1/5] added solution --- src/App.tsx | 112 ++++++++--------------- src/components/Pagination/Pagination.tsx | 82 ++++++++++++++++- src/utils.ts | 10 ++ 3 files changed, 128 insertions(+), 76 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 189a990c8..49404ae21 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,25 +1,45 @@ -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}`); export const App: React.FC = () => { + const [currentPage, setCurrentPage] = useState(1); + const [perPage, setPerPage] = useState(5); + + function onPageChange(page: number): void { + if (page !== currentPage) { + setCurrentPage(page); + } + } + + const startIndex = (currentPage - 1) * perPage; + const calculatedEndIndex = startIndex + perPage; + const endIndex = Math.min(calculatedEndIndex, items.length); + return (

Items with Pagination

- Page 1 (items 1 - 5 of 42) + {`Page ${currentPage} (items ${startIndex + 1} - ${endIndex} of ${items.length})`}

+ {/* зміна items на сторінці */}