@@ -23,7 +23,9 @@ const {
23
23
function processProps ( props ) {
24
24
const { initialDates, maxDate, minDate, selectionType } = props ;
25
25
const maxLimit = maxDate ? normalizeDate ( new Date ( maxDate ) , 23 , 59 , 59 , 999 ) : null ;
26
- const renderDate = normalizeDate ( ( ( initialDates && initialDates . length ) ? new Date ( initialDates [ 0 ] ) : new Date ( ) ) ) ;
26
+ const renderDate = normalizeDate ( ( ( initialDates && initialDates . length && initialDates [ 0 ] )
27
+ ? new Date ( initialDates [ 0 ] )
28
+ : new Date ( ) ) ) ;
27
29
28
30
let minLimit = minDate ? normalizeDate ( new Date ( minDate ) ) : null ;
29
31
let selectedDates = [ null , null ] ;
@@ -78,7 +80,25 @@ export default class Calendar extends Component {
78
80
}
79
81
80
82
componentWillReceiveProps ( newProps ) {
81
- this . setState ( ( ) => processProps ( newProps ) ) ;
83
+ const { initialDates, maxDate, minDate, selectionType } = newProps ;
84
+
85
+ let propsChanged = (
86
+ ( maxDate !== this . props . maxDate ) ||
87
+ ( minDate !== this . props . minDate ) ||
88
+ ( selectionType !== this . props . selectionType )
89
+ ) ;
90
+
91
+ if ( initialDates ) {
92
+ if ( this . props . initialDates ) {
93
+ propsChanged = propsChanged || initialDates . some ( ( item , idx ) => item !== this . props . initialDates [ idx ] ) ;
94
+ } else {
95
+ propsChanged = true ;
96
+ }
97
+ }
98
+
99
+ if ( propsChanged ) {
100
+ this . setState ( ( ) => processProps ( newProps ) ) ;
101
+ }
82
102
}
83
103
84
104
/**
0 commit comments