Skip to content

Commit 6abc253

Browse files
committed
fix: useEffectre-triggering due to incorrect dependency list being passed
prevents unnecessary api calls. the `monthStart`and `monthEnd`variables are date objects that cannot be compared for strict equal checks because on each re-render they lose their initial reference when a re-render occurs.
1 parent c4926a5 commit 6abc253

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

packages/web/src/views/Calendar/hooks/useWeek.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,25 @@ export const useWeek = (today: Dayjs) => {
3939
);
4040
}, [dispatch, end, start]);
4141

42+
const somedayEventsRequestFilter = useMemo(() => {
43+
return {
44+
startDate: monthStart.format(YEAR_MONTH_DAY_FORMAT),
45+
endDate: monthEnd.format(YEAR_MONTH_DAY_FORMAT),
46+
};
47+
}, [monthEnd, monthStart]);
48+
4249
useEffect(() => {
4350
dispatch(
4451
getSomedayEventsSlice.actions.request({
45-
startDate: monthStart.format(YEAR_MONTH_DAY_FORMAT),
46-
endDate: monthEnd.format(YEAR_MONTH_DAY_FORMAT),
52+
...somedayEventsRequestFilter,
4753
}),
4854
);
49-
}, [dispatch, monthEnd, monthStart]);
55+
// eslint-disable-next-line react-hooks/exhaustive-deps
56+
}, [
57+
dispatch,
58+
somedayEventsRequestFilter.startDate,
59+
somedayEventsRequestFilter.endDate,
60+
]);
5061

5162
useEffect(() => {
5263
dispatch(

0 commit comments

Comments
 (0)