react-contains-node
v0.3.0
Published
Check React Fiber ancestry between DOM elements.
Maintainers
Readme
react-contains-node
Check whether a DOM element is an ancestor of another element in the React Fiber tree.
Unlike Element.contains(), this also works across React portals.
Installation
npm install react-contains-nodeUsage
import {unstable_containsNode} from 'react-contains-node';
const isInside = unstable_containsNode(parentElement, childElement);
console.log(isInside);Why?
Element.contains() checks the DOM tree:
parentElement.contains(childElement);unstable_containsNode() checks the React Fiber tree, making it useful when React portals are involved.
Note
This package relies on React's internal Fiber properties (__reactFiber$...) and may break with future React versions.
