Skip to content

Commit

Permalink
fix: prevent to rerender when year or month has changed if daysInMont…
Browse files Browse the repository at this point in the history
…h was equals to its prev value
  • Loading branch information
ali-master committed Jun 11, 2021
1 parent 23ec235 commit 3ca1c99
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/hooks/usePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,24 @@ export function usePicker(props: WheelPickerProps) {
// Calculate days in selected months
useEffect(() => {
if (!isObjectEmpty(selectedDate)) {
const $daysInMonth = calculateDaysInMonth(
Number(selectedDate.year),
Number(selectedDate.month),
);
if (
previousSelectedDate?.month !== selectedDate?.month ||
previousSelectedDate?.year !== selectedDate?.year
(previousSelectedDate?.month !== selectedDate?.month ||
previousSelectedDate?.year !== selectedDate?.year) &&
daysInMonth !== $daysInMonth
) {
setDaysInMonth(
calculateDaysInMonth(
Number(selectedDate.year),
Number(selectedDate.month),
),
);
setDaysInMonth($daysInMonth);
}
}
}, [selectedDate, previousSelectedDate?.year, previousSelectedDate?.month]);
}, [
selectedDate.month,
selectedDate.year,
previousSelectedDate?.year,
previousSelectedDate?.month,
]);

// Handlers
/**
Expand Down

0 comments on commit 3ca1c99

Please sign in to comment.