Skip to content

Commit

Permalink
Preserve selectedStartDate in state on props update
Browse files Browse the repository at this point in the history
Currently, in `componentWillReceiveProps`, we always set `selectedStartDate` to be null. This can lead to buggy behavior when selectedStartDate was already set to something, as alluded to in these issues:

onefinestay#224
onefinestay#203

This issue will arise when the onSelectStart callback in the parent component does something that leads to changes in prop values passed into <DateRangePicker>, which will lead to `selectedStartDate` in state to be reset. Keeping selectedStartDate whatever value it was in componentWillReceiveProps will fix this issue.
  • Loading branch information
wheywu committed Nov 19, 2020
1 parent c73c92a commit f8cbc5f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/DateRangePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const DateRangePicker = createClass({
const nextEnabledRange = this.getEnabledRange(nextProps);

const updatedState = {
selectedStartDate: null,
selectedStartDate: this.state.selectedStartDate,
hideSelection: false,
dateStates: this.state.dateStates && Immutable.is(this.state.dateStates, nextDateStates) ? this.state.dateStates : nextDateStates,
enabledRange: this.state.enabledRange && this.state.enabledRange.isSame(nextEnabledRange) ? this.state.enabledRange : nextEnabledRange,
Expand Down

0 comments on commit f8cbc5f

Please sign in to comment.