β¬ οΈ Back to Table of Contents
π useParentElement¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 2 |
| π¦ Imports | 8 |
| π’ Vue Composition API | 1 |
π Table of Contents¶
π οΈ File Location:¶
π packages/core/useParentElement/index.ts
π¦ Imports¶
| Name | Source |
|---|---|
MaybeRefOrGetter |
vue |
ShallowRef |
vue |
tryOnMounted |
@vueuse/shared |
shallowRef |
vue |
toValue |
vue |
watch |
vue |
unrefElement |
../unrefElement |
useCurrentElement |
../useCurrentElement |
Vue Composition API¶
| Name | Type | Reactive Variables | Composables |
|---|---|---|---|
watch |
watch | none | none |
Functions¶
useParentElement(element: MaybeRefOrGetter<HTMLElement | SVGElemeβ¦): Readonly<ShallowRef<HTMLElement | SVGElement | null | undef⦶
Parameters:
elementMaybeRefOrGetter<HTMLElement | SVGElement | null | undefined>
Returns: Readonly<ShallowRef<HTMLElement | SVGElement | null | undefined>>
Calls:
shallowRef (from vue)unrefElement (from ../unrefElement)tryOnMounted (from @vueuse/shared)watch (from vue)toValue (from vue)
Code
export function useParentElement(
element: MaybeRefOrGetter<HTMLElement | SVGElement | null | undefined> = useCurrentElement<HTMLElement | SVGAElement>(),
): Readonly<ShallowRef<HTMLElement | SVGElement | null | undefined>> {
const parentElement = shallowRef<HTMLElement | SVGElement | null | undefined>()
const update = () => {
const el = unrefElement(element)
if (el)
parentElement.value = el.parentElement
}
tryOnMounted(update)
watch(() => toValue(element), update)
return parentElement
}
Internal helpers¶
Declared inside another function in this file.
update(): void¶
Returns: void
Calls:
unrefElement (from ../unrefElement)
Generated by Syntax Scribe