Skip to content

Commit

Permalink
Don't assume that setState is synchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Meed committed Aug 8, 2017
1 parent f346e9a commit fd064d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/components/DayPickerRangeController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,16 @@ export default class DayPickerRangeController extends React.Component {
const prevMonth = currentMonth.clone().subtract(2, 'months');
const prevMonthVisibleDays = getVisibleDays(prevMonth, 1, enableOutsideDays, true);

const newCurrentMonth = currentMonth.clone().subtract(1, 'month');
this.setState({
currentMonth: currentMonth.clone().subtract(1, 'month'),
currentMonth: newCurrentMonth,
visibleDays: {
...newVisibleDays,
...this.getModifiers(prevMonthVisibleDays),
},
});

onPrevMonthClick(this.state.currentMonth.clone());
onPrevMonthClick(newCurrentMonth);
}

onNextMonthClick() {
Expand All @@ -514,15 +515,16 @@ export default class DayPickerRangeController extends React.Component {
const nextMonth = currentMonth.clone().add(numberOfMonths + 1, 'month');
const nextMonthVisibleDays = getVisibleDays(nextMonth, 1, enableOutsideDays, true);

const newCurrentMonth = currentMonth.clone().add(1, 'month');
this.setState({
currentMonth: currentMonth.clone().add(1, 'month'),
currentMonth: newCurrentMonth,
visibleDays: {
...newVisibleDays,
...this.getModifiers(nextMonthVisibleDays),
},
});

onNextMonthClick(this.state.currentMonth.clone());
onNextMonthClick(newCurrentMonth);
}

onMultiplyScrollableMonths() {
Expand Down
7 changes: 4 additions & 3 deletions src/components/DayPickerSingleDateController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export default class DayPickerSingleDateController extends React.Component {
},
});

onPrevMonthClick(this.state.currentMonth.clone());
onPrevMonthClick(prevMonth);
}

onNextMonthClick() {
Expand All @@ -346,15 +346,16 @@ export default class DayPickerSingleDateController extends React.Component {
const nextMonth = currentMonth.clone().add(numberOfMonths, 'month');
const nextMonthVisibleDays = getVisibleDays(nextMonth, 1, enableOutsideDays);

const newCurrentMonth = currentMonth.clone().add(1, 'month');
this.setState({
currentMonth: currentMonth.clone().add(1, 'month'),
currentMonth: newCurrentMonth,
visibleDays: {
...newVisibleDays,
...this.getModifiers(nextMonthVisibleDays),
},
});

onNextMonthClick(this.state.currentMonth.clone());
onNextMonthClick(newCurrentMonth);
}


Expand Down

0 comments on commit fd064d4

Please sign in to comment.