MCPcopy
hub / github.com/vexip-ui/vexip-ui / useMounted

Function useMounted

common/hooks/src/mounted.ts:3–23  ·  view source on GitHub ↗
(wait?: 'tick' | 'frame')

Source from the content-addressed store, hash-verified

1import { nextTick, onBeforeUnmount, onMounted, readonly, ref } from 'vue'
2
3export function useMounted(wait?: 'tick' | 'frame') {
4 const isMounted = ref(false)
5
6 const mount = () => (isMounted.value = true)
7
8 onMounted(() => {
9 if (wait === 'tick') {
10 nextTick(mount)
11 } else if (wait === 'frame') {
12 requestAnimationFrame(mount)
13 } else {
14 mount()
15 }
16 })
17
18 onBeforeUnmount(() => {
19 isMounted.value = false
20 })
21
22 return { isMounted: readonly(isMounted) }
23}

Callers 3

setupFunction · 0.90
setupFunction · 0.90
useScrollWrapperFunction · 0.90

Calls 1

mountFunction · 0.70

Tested by

no test coverage detected