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

DayPickerInput check for prop change with previous props rather than previous state #495

Merged
merged 3 commits into from
Sep 26, 2017
Merged

Conversation

kradical
Copy link
Contributor

Hello!

I filed this issue: #494.

I have tested this with dayPickerProps and without dayPickerProps.

@kradical kradical changed the title Check for prop change with previous props rather than state DayPickerInput check for prop change with previous props rather than previous state Sep 22, 2017
@codecov
Copy link

codecov bot commented Sep 22, 2017

Codecov Report

Merging #495 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #495   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          15     15           
  Lines         531    534    +3     
  Branches      109    111    +2     
=====================================
+ Hits          531    534    +3
Impacted Files Coverage Δ
src/DayPickerInput.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2a4e99b...5959f76. Read the comment docs.

Copy link
Owner

@gpbl gpbl left a comment

Choose a reason for hiding this comment

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

Hey thanks for your PR! I asked you to update the code a bit so we can understand better what's happening there. componentWillReceiveProps is a delicate part of the lifecycle and we want to avoid unforeseen bugs.

@@ -78,21 +78,28 @@ export default class DayPickerInput extends React.Component {
}

componentWillReceiveProps(nextProps) {
const { month, value } = this.state;
const hasDifferentValue = nextProps.value !== value;
const { dayPickerProps: { month }, value } = this.props;
Copy link
Owner

Choose a reason for hiding this comment

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

To make the code easier to understand, I usually avoid destructuring an object at the second level: could you please here just use:

const { dayPickerProps, value } = this.props;

and update the code below? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!


const hasDifferentValue = nextValue !== value;

const monthExistsOnBoth = nextMonth && month;
Copy link
Owner

Choose a reason for hiding this comment

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

So this would become:

const monthExistsOnBoth = nextDayPickerProps.month && dayPickerProps.month;

I'd change the variable name from monthsExistsOnBoth to willUpdateDayPickerMonth (I don't understand what both are or why a month should exist or not :))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

very true, will update tomorrow!

const {
dayPickerProps: { month: nextMonth },
value: nextValue,
} = nextProps;
Copy link
Owner

Choose a reason for hiding this comment

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

Here also:

dayPickerProps: nextDayPickerProps,

I know it's a bit more verbose, but it would really help!

@gpbl gpbl merged commit abffd24 into gpbl:master Sep 26, 2017
@gpbl gpbl added this to the v6.1.1 milestone Sep 26, 2017
@gpbl
Copy link
Owner

gpbl commented Sep 26, 2017

Thanks!

@kradical kradical deleted the prChanges branch September 26, 2017 08:12
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.

2 participants