Skip to content

⬅️ Back to Table of Contents

📄 useCurrentElement

📊 Analysis Summary

Metric Count
🔧 Functions 1
📦 Imports 9

📚 Table of Contents

🛠️ File Location:

📂 packages/core/useCurrentElement/index.ts

📦 Imports

Name Source
IsAny @vueuse/shared
MaybeElement ../unrefElement
MaybeElementRef ../unrefElement
VueInstance ../unrefElement
computedWithControl @vueuse/shared
getCurrentInstance vue
onMounted vue
onUpdated vue
unrefElement ../unrefElement

Functions

useCurrentElement(rootComponent: MaybeElementRef<R>): any

Parameters:

  • rootComponent MaybeElementRef<R>

Returns: any

Calls:

  • getCurrentInstance (from vue)
  • computedWithControl (from @vueuse/shared)
  • unrefElement (from ../unrefElement)
  • onUpdated (from vue)
  • onMounted (from vue)
Code
export function useCurrentElement<
  T extends MaybeElement = MaybeElement,
  R extends VueInstance = VueInstance,
  E extends MaybeElement = MaybeElement extends T ? IsAny<R['$el']> extends false ? R['$el'] : T : T,
>(
  rootComponent?: MaybeElementRef<R>,
) {
  const vm = getCurrentInstance()!
  const currentElement = computedWithControl(
    () => null,
    () => (rootComponent ? unrefElement(rootComponent) : vm.proxy!.$el) as E,
  )

  onUpdated(currentElement.trigger)
  onMounted(currentElement.trigger)

  return currentElement
}

Generated by Syntax Scribe