Skip to content

Commit 4666e26

Browse files
committed
fix: update
1 parent 16ef72b commit 4666e26

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

packages/blade/src/components/DatePicker/Calendar.web.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const Calendar = <Type extends DateSelectionType>({
6666

6767
const dateContext = useDatesContext();
6868
const isMobile = useIsMobile();
69-
const currentDate = () => {
69+
const currentDate = React.useMemo(() => {
7070
if (_date) {
7171
return _date;
7272
}
@@ -77,44 +77,44 @@ const Calendar = <Type extends DateSelectionType>({
7777
return oldValue;
7878
}
7979
return shiftTimezone('add', new Date());
80-
};
80+
}, [_date, oldValue]);
8181
const numberOfColumns = isMobile || !isRange ? 1 : 2;
8282
const columnsToScroll = numberOfColumns;
8383

8484
const handleNextMonth = () => {
85-
const nextDate = dayjs(currentDate()).add(columnsToScroll, 'month').toDate();
85+
const nextDate = dayjs(currentDate).add(columnsToScroll, 'month').toDate();
8686
onNext?.({ date: nextDate, type: 'month' });
8787
setDate(nextDate);
8888
};
8989

9090
const handlePreviousMonth = () => {
91-
const nextDate = dayjs(currentDate()).subtract(columnsToScroll, 'month').toDate();
91+
const nextDate = dayjs(currentDate).subtract(columnsToScroll, 'month').toDate();
9292
onPrevious?.({ date: nextDate, type: 'month' });
9393
setDate(nextDate);
9494
};
9595

9696
const handleNextYear = () => {
97-
const nextDate = dayjs(currentDate()).add(columnsToScroll, 'year').toDate();
97+
const nextDate = dayjs(currentDate).add(columnsToScroll, 'year').toDate();
9898
onNext?.({ date: nextDate, type: 'year' });
9999
setDate(nextDate);
100100
};
101101

102102
const handlePreviousYear = () => {
103-
const nextDate = dayjs(currentDate()).subtract(columnsToScroll, 'year').toDate();
103+
const nextDate = dayjs(currentDate).subtract(columnsToScroll, 'year').toDate();
104104
onPrevious?.({ date: nextDate, type: 'year' });
105105
setDate(nextDate);
106106
};
107107

108108
const handleNextDecade = () => {
109-
const nextDate = dayjs(currentDate())
109+
const nextDate = dayjs(currentDate)
110110
.add(10 * columnsToScroll, 'year')
111111
.toDate();
112112
onNext?.({ date: nextDate, type: 'decade' });
113113
setDate(nextDate);
114114
};
115115

116116
const handlePreviousDecade = () => {
117-
const nextDate = dayjs(currentDate())
117+
const nextDate = dayjs(currentDate)
118118
.subtract(10 * columnsToScroll, 'year')
119119
.toDate();
120120
onPrevious?.({ date: nextDate, type: 'decade' });
@@ -131,7 +131,7 @@ const Calendar = <Type extends DateSelectionType>({
131131
>
132132
<CalendarHeader
133133
isRange={isRange}
134-
date={currentDate()}
134+
date={currentDate}
135135
onLevelChange={(level) => setLevel(() => level)}
136136
pickerType={levelToPicker[level] as PickerType}
137137
onNextMonth={handleNextMonth}
@@ -142,11 +142,11 @@ const Calendar = <Type extends DateSelectionType>({
142142
onPreviousYear={handlePreviousYear}
143143
showLevelChangeLink={showLevelChangeLink}
144144
/>
145-
<CalendarGradientStyles isRange={isRange} date={currentDate()}>
145+
<CalendarGradientStyles isRange={isRange} date={currentDate}>
146146
<DatePicker
147147
withCellSpacing={false}
148148
type={isRange ? 'range' : 'default'}
149-
date={currentDate()}
149+
date={currentDate}
150150
locale={dateContext.locale}
151151
level={level}
152152
onDateChange={setDate}

0 commit comments

Comments
 (0)