Skip to content

useParentElement

Category
Export Size
187 B
Last Changed
5 days ago

Get parent element of the given element

Demo

Usage

tsx
import { 
useParentElement
} from '@reause/core'
import {
useRef
} from 'react'
const
childRef
=
useRef
<HTMLDivElement>(null)
const
parent
=
useParentElement
(
childRef
) // HTMLElement | SVGElement | null | undefined

Type Declarations

ts
type ElementSource = HTMLElement | SVGElement | null | undefined

export function useParentElement(element?: RefObject<ElementSource>): ElementSource

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
d2b07 - fix(core): resolve useParentElement audit findings (#615)
8fddc - chore!: remove all Vue-only Maybe* types and getter unions, adopt React Ref (#462)

Released under the MIT License. v0.1.8