Skip to content

Commit f30ccf0

Browse files
authored
fix(useInfiniteScroll): stop watch when unmounted (#4110)
1 parent 3b94de4 commit f30ccf0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/core/useInfiniteScroll/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Awaitable, MaybeRefOrGetter } from '@vueuse/shared'
2-
import { toValue } from '@vueuse/shared'
2+
import { toValue, tryOnUnmounted } from '@vueuse/shared'
33
import type { UnwrapNestedRefs } from 'vue-demi'
44
import { computed, nextTick, reactive, ref, watch } from 'vue-demi'
55
import { useElementVisibility } from '../useElementVisibility'
@@ -101,12 +101,14 @@ export function useInfiniteScroll<T extends InfiniteScrollElement>(
101101
}
102102
}
103103

104-
watch(
104+
const stop = watch(
105105
() => [state.arrivedState[direction], isElementVisible.value],
106106
checkAndLoad,
107107
{ immediate: true },
108108
)
109109

110+
tryOnUnmounted(stop)
111+
110112
return {
111113
isLoading,
112114
reset() {

0 commit comments

Comments
 (0)