Skip to content

Latest commit

 

History

History
39 lines (25 loc) · 858 Bytes

use-parent.md

File metadata and controls

39 lines (25 loc) · 858 Bytes
description
Retrieve a node higher than the current webcomponent.

use-parent

Module

import { useParent, useParentPath } from "@atomico/hooks/use-parent";

Syntax useParent

const selector = "form";
const parent = useParent(selector);

Where:

  • selector: String, Selector to be used by Element.matches when searching for the parent.
  • parent: Element, ascending search result according to selector.

Syntax useParentPath

const parents = useParentPath(composed?: boolean);

Where:

  • parents: parent nodes of the webcomponent
  • composed: bypasses shadow DOM in parent capture.

Example

{% embed url="https://webcomponents.dev/edit/collection/n2tZyzx4LMKqk1jNE0e9/OVpU1DQvmGjhYSf3Iqbu/src/index.jsx" %}