From f8cbc5fa76ab6c99e4ed3fff7023edec52c157c4 Mon Sep 17 00:00:00 2001 From: Wei Wu <47542009+wheywu@users.noreply.github.com> Date: Wed, 18 Nov 2020 17:58:05 -0800 Subject: [PATCH] Preserve selectedStartDate in state on props update 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: https://github.com/onefinestay/react-daterange-picker/issues/224 https://github.com/onefinestay/react-daterange-picker/issues/203 This issue will arise when the onSelectStart callback in the parent component does something that leads to changes in prop values passed into , which will lead to `selectedStartDate` in state to be reset. Keeping selectedStartDate whatever value it was in componentWillReceiveProps will fix this issue. --- src/DateRangePicker.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DateRangePicker.jsx b/src/DateRangePicker.jsx index eb4bfb8e..7ca2d909 100644 --- a/src/DateRangePicker.jsx +++ b/src/DateRangePicker.jsx @@ -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,