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

Ensuring callbacks will execute after new state is ready. #990

Merged
merged 4 commits into from
Feb 1, 2018

Conversation

iliran11
Copy link
Contributor

@iliran11 iliran11 commented Jan 30, 2018

onNextMonthClick and onPrevMonthClick callbacks were seemingly executing right after updating the state of DayPickerSingleDateController.jsx.

However, It is not ensured and might cause some unexpected behavior caused by callbacks executing before the state update was completed (happened in my work project).

it is also a documented pitfall on react documentations.

setState() does not always immediately update the component. It may batch or defer the update until later. This makes reading this.state right after calling setState() a potential pitfall.

@coveralls
Copy link

coveralls commented Jan 30, 2018

Coverage Status

Coverage remained the same at 86.782% when pulling bf25755 on iliran11:master into 7dfe618 on airbnb:master.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Thanks! Are there any other components that should get this treatment?

@ljharb ljharb added the semver-patch: fixes/refactors/etc Anything that's not major or minor. label Jan 31, 2018
@iliran11
Copy link
Contributor Author

iliran11 commented Jan 31, 2018

Not that i'm aware of. i think it's the minimal required fix for now :)

@majapw
Copy link
Collaborator

majapw commented Jan 31, 2018

@iliran11 can you make this change in the DayPickerRangeController as well? Otherwise, looks good to me!

@@ -645,9 +645,10 @@ export default class DayPickerRangeController extends React.Component {
...newVisibleDays,
...this.getModifiers(nextMonthVisibleDays),
},
}, () => {
onNextMonthClick(newCurrentMonth.clone());
});

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to delete this blank line

@iliran11
Copy link
Contributor Author

iliran11 commented Feb 1, 2018

@majapw - done! ;)

@majapw
Copy link
Collaborator

majapw commented Feb 1, 2018

Sweet, thanks!

@majapw majapw merged commit 79a2d56 into react-dates:master Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch: fixes/refactors/etc Anything that's not major or minor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants