@@ -66,7 +66,7 @@ const Calendar = <Type extends DateSelectionType>({
66
66
67
67
const dateContext = useDatesContext ( ) ;
68
68
const isMobile = useIsMobile ( ) ;
69
- const currentDate = ( ) => {
69
+ const currentDate = React . useMemo ( ( ) => {
70
70
if ( _date ) {
71
71
return _date ;
72
72
}
@@ -77,44 +77,44 @@ const Calendar = <Type extends DateSelectionType>({
77
77
return oldValue ;
78
78
}
79
79
return shiftTimezone ( 'add' , new Date ( ) ) ;
80
- } ;
80
+ } , [ _date , oldValue ] ) ;
81
81
const numberOfColumns = isMobile || ! isRange ? 1 : 2 ;
82
82
const columnsToScroll = numberOfColumns ;
83
83
84
84
const handleNextMonth = ( ) => {
85
- const nextDate = dayjs ( currentDate ( ) ) . add ( columnsToScroll , 'month' ) . toDate ( ) ;
85
+ const nextDate = dayjs ( currentDate ) . add ( columnsToScroll , 'month' ) . toDate ( ) ;
86
86
onNext ?.( { date : nextDate , type : 'month' } ) ;
87
87
setDate ( nextDate ) ;
88
88
} ;
89
89
90
90
const handlePreviousMonth = ( ) => {
91
- const nextDate = dayjs ( currentDate ( ) ) . subtract ( columnsToScroll , 'month' ) . toDate ( ) ;
91
+ const nextDate = dayjs ( currentDate ) . subtract ( columnsToScroll , 'month' ) . toDate ( ) ;
92
92
onPrevious ?.( { date : nextDate , type : 'month' } ) ;
93
93
setDate ( nextDate ) ;
94
94
} ;
95
95
96
96
const handleNextYear = ( ) => {
97
- const nextDate = dayjs ( currentDate ( ) ) . add ( columnsToScroll , 'year' ) . toDate ( ) ;
97
+ const nextDate = dayjs ( currentDate ) . add ( columnsToScroll , 'year' ) . toDate ( ) ;
98
98
onNext ?.( { date : nextDate , type : 'year' } ) ;
99
99
setDate ( nextDate ) ;
100
100
} ;
101
101
102
102
const handlePreviousYear = ( ) => {
103
- const nextDate = dayjs ( currentDate ( ) ) . subtract ( columnsToScroll , 'year' ) . toDate ( ) ;
103
+ const nextDate = dayjs ( currentDate ) . subtract ( columnsToScroll , 'year' ) . toDate ( ) ;
104
104
onPrevious ?.( { date : nextDate , type : 'year' } ) ;
105
105
setDate ( nextDate ) ;
106
106
} ;
107
107
108
108
const handleNextDecade = ( ) => {
109
- const nextDate = dayjs ( currentDate ( ) )
109
+ const nextDate = dayjs ( currentDate )
110
110
. add ( 10 * columnsToScroll , 'year' )
111
111
. toDate ( ) ;
112
112
onNext ?.( { date : nextDate , type : 'decade' } ) ;
113
113
setDate ( nextDate ) ;
114
114
} ;
115
115
116
116
const handlePreviousDecade = ( ) => {
117
- const nextDate = dayjs ( currentDate ( ) )
117
+ const nextDate = dayjs ( currentDate )
118
118
. subtract ( 10 * columnsToScroll , 'year' )
119
119
. toDate ( ) ;
120
120
onPrevious ?.( { date : nextDate , type : 'decade' } ) ;
@@ -131,7 +131,7 @@ const Calendar = <Type extends DateSelectionType>({
131
131
>
132
132
< CalendarHeader
133
133
isRange = { isRange }
134
- date = { currentDate ( ) }
134
+ date = { currentDate }
135
135
onLevelChange = { ( level ) => setLevel ( ( ) => level ) }
136
136
pickerType = { levelToPicker [ level ] as PickerType }
137
137
onNextMonth = { handleNextMonth }
@@ -142,11 +142,11 @@ const Calendar = <Type extends DateSelectionType>({
142
142
onPreviousYear = { handlePreviousYear }
143
143
showLevelChangeLink = { showLevelChangeLink }
144
144
/>
145
- < CalendarGradientStyles isRange = { isRange } date = { currentDate ( ) } >
145
+ < CalendarGradientStyles isRange = { isRange } date = { currentDate } >
146
146
< DatePicker
147
147
withCellSpacing = { false }
148
148
type = { isRange ? 'range' : 'default' }
149
- date = { currentDate ( ) }
149
+ date = { currentDate }
150
150
locale = { dateContext . locale }
151
151
level = { level }
152
152
onDateChange = { setDate }
0 commit comments