-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass currentMonth into onPrevMonthClick and onNextMonthClick #667
Pass currentMonth into onPrevMonthClick and onNextMonthClick #667
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment!
@@ -499,7 +499,7 @@ export default class DayPickerRangeController extends React.Component { | |||
}, | |||
}); | |||
|
|||
onPrevMonthClick(); | |||
onPrevMonthClick(this.state.currentMonth.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So currentMonth
is already available to you as a destructured aspect of state. What you probably want to pass down is the new month anyways, no?
if you expect this.state.currentMonth
to equal currentMonth.clone().subtract(1, 'month')
at this point, you're probably going to have a bad time (setting state is not synchronous in the way you are expecting). Better to set that to a separate variable and then update and also pass back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was intending to pass the new month.
✅ Fixed, fd064d4.
this.setState({ | ||
currentMonth: currentMonth.clone().subtract(1, 'month'), | ||
currentMonth: newCurrentMonth, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it miiiight be a good idea to return a different clone to the callback as the one in the state... just in case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. ✅ Fixed, 1c4bc4e.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Sometimes it's helpful to know what month is currently showing on the calendar (for instance, to fetch data on blocked or highlighted dates for upcoming months). This change adds the current month as an argument to the
onPrevMonthClick
andonNextMonthClick
callbacks, allowing parent components to know the currently-displayed month.This change also adds Mocha specs, which pass (I hope).
Alex Meed