Skip to content

Commit 267c116

Browse files
committed
latest
1 parent 59ea8f3 commit 267c116

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/motion/src/utils/use-in-view.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import type { Ref } from 'vue'
21
import { ref, unref, watchEffect } from 'vue'
32
import type { Options } from '@/types/state'
43
import { inView } from 'framer-motion/dom'
5-
import type { MaybeRef } from '@vueuse/core'
4+
import { type MaybeComputedElementRef, type MaybeRef, unrefElement } from '@vueuse/core'
65

76
type InViewOptions = Options['inViewOptions']
87
export interface UseInViewOptions extends Omit<InViewOptions, 'root'> {
98
root?: MaybeRef<Element | Document>
109
}
1110

12-
export function useInView<T extends Element = any>(
13-
domRef: Ref<T | null>,
11+
export function useInView(
12+
domRef: MaybeComputedElementRef,
1413
options?: MaybeRef<UseInViewOptions>,
1514
) {
1615
const isInView = ref(false)
1716

1817
watchEffect((onCleanup) => {
1918
const realOptions = unref(options) || {}
2019
const { once } = realOptions
21-
if (!domRef.value || (once && isInView.value)) {
20+
const el = unrefElement(domRef)
21+
if (!el || (once && isInView.value)) {
2222
return
2323
}
2424
const onEnter = () => {
@@ -29,7 +29,7 @@ export function useInView<T extends Element = any>(
2929
isInView.value = false
3030
}
3131
}
32-
const cleanup = inView(domRef.value, onEnter, {
32+
const cleanup = inView(el, onEnter, {
3333
...realOptions,
3434
root: unref(realOptions.root),
3535
})

0 commit comments

Comments
 (0)