Skip to content
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

Conversation

MathSquared
Copy link

@MathSquared MathSquared commented Aug 8, 2017

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 and onNextMonthClick callbacks, allowing parent components to know the currently-displayed month.

This change also adds Mocha specs, which pass (I hope).

Alex Meed

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.243% when pulling f346e9a on MathSquared:alex-meed-next-prev-callbacks-receive-date into d32e9b3 on airbnb:master.

Copy link
Collaborator

@majapw majapw left a 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());
Copy link
Collaborator

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.

Copy link
Author

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.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 86.273% when pulling fd064d4 on MathSquared:alex-meed-next-prev-callbacks-receive-date into d32e9b3 on airbnb:master.

this.setState({
currentMonth: currentMonth.clone().subtract(1, 'month'),
currentMonth: newCurrentMonth,
Copy link
Collaborator

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.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch.  ✅  Fixed, 1c4bc4e.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 86.273% when pulling 1c4bc4e on MathSquared:alex-meed-next-prev-callbacks-receive-date into d32e9b3 on airbnb:master.

Copy link
Collaborator

@majapw majapw left a comment

Choose a reason for hiding this comment

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

LGTM!

@majapw majapw merged commit 00164cb into react-dates:master Aug 9, 2017
@MathSquared MathSquared deleted the alex-meed-next-prev-callbacks-receive-date branch August 9, 2017 00:37
@adacosta adacosta mentioned this pull request Aug 27, 2017
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.

None yet

3 participants