Skip to content

Comments

add task solution#1429

Open
butko9595 wants to merge 2 commits intomate-academy:masterfrom
butko9595:develop
Open

add task solution#1429
butko9595 wants to merge 2 commits intomate-academy:masterfrom
butko9595:develop

Conversation

@butko9595
Copy link

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great work on this! The pagination component is well-structured and most of the functionality is in place. However, I'm requesting a couple of changes to meet all the requirements.

The most critical issue is that the application state doesn't sync with the URL when using the browser's back and forward buttons. In src/App.tsx, you're initializing state from the URL with useState, which only runs on the initial render. To fix this, the URL should be the single source of truth. You can achieve this by removing the useState for currentPage and perPage and instead reading their values directly from useSearchParams on every render.

Additionally, in src/components/Pagination/Pagination.tsx, the task requires the currentPage prop to be optional with a default value of 1. Please update the Props type to make it optional and provide the default value in the component signature.

Once these two points are addressed, your solution will be perfect. Keep up the excellent effort!


✨ 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines 6 to 13
currentPage: number;
onPageChange: (page: number) => void;
};

export const Pagination: React.FC<Props> = ({
total,
perPage,
currentPage,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task description specifies that the currentPage prop should be optional with a default value of 1. Currently, it's defined as a required prop.

To meet the requirement, you should mark currentPage as optional in the Props type and provide a default value when destructuring props in the component signature.

src/App.tsx Outdated
Comment on lines 13 to 14
const [currentPage, setCurrentPage] = React.useState(pageFromUrl);
const [perPage, setPerPage] = React.useState(perPageFromUrl);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initializing state from the URL works for the initial page load, but it causes a problem with browser navigation. useState's initializer is only used during the first render. If the user clicks the back or forward button, the URL will change and the component will re-render, but currentPage and perPage will retain their old values from the state, leading to a mismatch between the URL and what's displayed.

To fix this, the URL should be the single source of truth. You can achieve this by removing useState for currentPage and perPage and instead deriving their values directly from searchParams on every render.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Excellent work on this iteration! I am approving your solution as you've successfully addressed all the previous feedback. The application now correctly uses the URL as the single source of truth for pagination state, and the Pagination component's props meet all requirements. The code is clean, well-structured, and fully functional. Great job!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants