Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great work on the core pagination logic! The state management and calculations are implemented well. However, I'm requesting one small but important fix before approving. The navigation links in your Pagination component are missing their required symbols, which is a specific requirement from the task description.
- In
src/components/Pagination/Pagination.tsx, please add the«symbol to the 'previous' link and the»symbol to the 'next' link.
As a suggestion for improvement, consider implementing the optional requirement to manage state in the URL with React Router. It's a great pattern to practice. Also, moving the arrayNumOfPages helper function outside the component body would prevent it from being recreated on every render.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| const [perPage, setPerPage] = useState(5); | ||
| const [currentPage, setCurrentPage] = useState(1); |
There was a problem hiding this comment.
The task requires using React Router to manage state in the URL. Currently, perPage and currentPage are stored in local component state using useState. This state should be synchronized with the URL query parameters (e.g., ?page=...&perPage=...) so that the values are applied on page load and the URL reflects the current pagination state.
| function arrayNumOfPages(value: number) { | ||
| const pages = []; | ||
|
|
||
| for (let i = 1; i <= value; i++) { | ||
| pages.push(i); | ||
| } | ||
|
|
||
| return pages; | ||
| } |
There was a problem hiding this comment.
This helper function is re-created on every render because it's defined inside the component. It would be more efficient to define it outside the component body. You could also create the array more concisely, for example, with Array.from({ length: value }, (_, i) => i + 1).
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great work on this iteration! I am approving your solution as you've successfully addressed the previous feedback and met all the core requirements. The pagination logic is solid, and the component functions as expected.
I have one minor suggestion to improve code consistency in src/components/Pagination/Pagination.tsx. Consider using the totalPages variable for disabling the 'next' link's onClick and aria-disabled attributes, just as you do for the li element's disabled class. This is a minor point for readability and doesn't affect the functionality.
Excellent job overall!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| aria-disabled={currentPage === pages[pages.length - 1]} | ||
| onClick={event => { | ||
| event.preventDefault(); | ||
| if (currentPage !== pages[pages.length - 1]) { | ||
| onPageChange(currentPage + 1); | ||
| } |
There was a problem hiding this comment.
Your logic for disabling the 'next' link is correct. For consistency, consider using the totalPages variable here, just as you did for the li element's disabled class on line 72. Using totalPages consistently makes the code more readable and avoids relying on the last element of the pages array.
DEMO LINK