fix: you should not be able to go further than the last date #49
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.
What does this change do?
If the developer has specified a minDate and the user arrives at the last possible page but continues to hit the previous button, the date will continue to be modified and will therefore put them in a "negative" state, so that when they hit the next button, the calendar does not move to the next month.
The same is true for a maxDate and the next button.
This change fixes it so that continuing to push the previous button will not put the user into a "negative" state.
Why was this happening?
The date being passed into the
goToPrevNext
function is a reference to the state of the calendar. Since it is only a reference, when we add time to it, it is actually mutating the state in a way that is invisible to react. This causes the date to change without calling the setState function and without changing the reference. Not only is changing the state at this moment not wanted, but React is also unaware of the change and does not know to rerender.To fix this, we need to clone the date so that the state's version is not being mutated.