@@ -16,6 +16,7 @@ import { useMount, useUpdateEffect } from '../hooks';
16
16
import { isDate } from '../utils/validate/date' ;
17
17
import { padZero } from '../utils' ;
18
18
import { doubleRaf } from '../utils/raf' ;
19
+ import useRefState from '../hooks/use-ref-state' ;
19
20
20
21
const DatePicker = forwardRef < DateTimePickerInstance , DatePickerProps > ( ( props , ref ) => {
21
22
const {
@@ -41,8 +42,7 @@ const DatePicker = forwardRef<DateTimePickerInstance, DatePickerProps>((props, r
41
42
} ;
42
43
43
44
const pickerRef = useRef < PickerInstance > ( null ) ;
44
- const [ currentDate , setCurrentDate ] = useState ( formatValue ( value ) ) ;
45
- const currentDateRef = useRef < Date > ( currentDate ) ;
45
+ const [ currentDate , setCurrentDate , currentDateRef ] = useRefState ( formatValue ( value ) ) ;
46
46
47
47
const getBoundary = ( type : 'max' | 'min' , dateValue : Date ) => {
48
48
const boundary = props [ `${ type } Date` ] ;
@@ -136,7 +136,7 @@ const DatePicker = forwardRef<DateTimePickerInstance, DatePickerProps>((props, r
136
136
}
137
137
138
138
return result ;
139
- } , [ columnsOrder , props . type ] ) ;
139
+ } , [ columnsOrder , props . type , currentDateRef . current ] ) ;
140
140
141
141
const originColumns = useMemo (
142
142
( ) =>
@@ -237,7 +237,6 @@ const DatePicker = forwardRef<DateTimePickerInstance, DatePickerProps>((props, r
237
237
const indexes = pickerRef . current . getIndexes ( ) ;
238
238
const nextValue = updateInnerValue ( indexes ) ;
239
239
setCurrentDate ( nextValue ) ;
240
- currentDateRef . current = nextValue ;
241
240
props . onChange ?.( nextValue ) ;
242
241
}
243
242
} ;
@@ -252,7 +251,6 @@ const DatePicker = forwardRef<DateTimePickerInstance, DatePickerProps>((props, r
252
251
const indexes = pickerRef . current ?. getIndexes ( ) ;
253
252
const nextValue = updateInnerValue ( indexes ) ;
254
253
setCurrentDate ( nextValue ) ;
255
- currentDateRef . current = nextValue ;
256
254
}
257
255
} , 0 ) ;
258
256
} ) ;
@@ -268,7 +266,6 @@ const DatePicker = forwardRef<DateTimePickerInstance, DatePickerProps>((props, r
268
266
269
267
if ( nextValue && nextValue . valueOf ( ) !== currentDate ?. valueOf ( ) ) {
270
268
setCurrentDate ( nextValue ) ;
271
- currentDateRef . current = nextValue ;
272
269
}
273
270
} , [ value , filter , minDate , maxDate ] ) ;
274
271
0 commit comments