Skip to content

Commit 3b9f29c

Browse files
authored
Fix date picker re-renders by breaking debounce loop (#2874)
fix date picker re-renders by breaking debounce loop
1 parent e40d1ea commit 3b9f29c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

app/components/form/fields/DateTimeRangePicker.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,15 @@ export function useDateTimeRangePicker({
8484
items,
8585
}
8686

87-
const [startTime] = useDebounce(range.start.toDate(tz), 400)
88-
const [endTime] = useDebounce(range.end.toDate(tz), 400)
87+
// Without these useMemos, we get re-renders every 400ms because when the
88+
// debounce timeout expires, it updates the value, which triggers a render for
89+
// itself because the time gets remade by toDate() (i.e., even though it is
90+
// the same time, it is a new object)
91+
const rangeStart = useMemo(() => range.start.toDate(tz), [range.start])
92+
const [startTime] = useDebounce(rangeStart, 400)
93+
94+
const rangeEnd = useMemo(() => range.end.toDate(tz), [range.end])
95+
const [endTime] = useDebounce(rangeEnd, 400)
8996

9097
return {
9198
startTime,

0 commit comments

Comments
 (0)