c219d87a69
* use `ownerDocument` instead of `document` This should ensure that in iframes and new windows the correct document is being used. * update changelog
14 lines
422 B
TypeScript
14 lines
422 B
TypeScript
import { MutableRefObject } from 'react'
|
|
|
|
export function getOwnerDocument<T extends Element | MutableRefObject<Element | null>>(
|
|
element: T | null | undefined
|
|
) {
|
|
if (typeof window === 'undefined') return null
|
|
if (element instanceof Node) return element.ownerDocument
|
|
if (element?.hasOwnProperty('current')) {
|
|
if (element.current instanceof Node) return element.current.ownerDocument
|
|
}
|
|
|
|
return document
|
|
}
|