This repository has been archived by the owner on Oct 17, 2020. It is now read-only.
Fix Page control index when total number of pages changes #748
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #658.
Current Behavior ( Optional for new feature )
Description
If page is changed to a page whose number is greater than total amount of pages (can happen when number of pages changes in between page changes), then the current page will still be set to that page instead of falling back to the new last page.
Screenshots
See #658
New Behavior
Description
Now when the total number of pages changes after a page change, the page selected will fall back to the last page.
Screenshots
Note
This solution uses
getDerivedStateFromProps
, which is not a recommended approach to handling derived state. An alternative solution would be letting the parent ofPageControl
component control the current index, but I think this will introduce unneeded complexity. Additionally, the logic within thegetDerivedStateFromProps
method will not override any local changes to thecurrentPageIdx
value if it's less than or equal to the total number of pages, which is expected behaviour.