ConvoyPanel/resources/scripts/util/owner.ts
2022-11-21 06:16:27 +00:00

14 lines
No EOL
433 B
TypeScript

import { MutableRefObject } from 'react'
import { isServer } from './ssr'
export function getOwnerDocument<T extends Element | MutableRefObject<Element | null>>(
element: T | null | undefined
) {
if (isServer) return null
if (element instanceof Node) return element.ownerDocument
if (element?.hasOwnProperty('current')) {
if (element.current instanceof Node) return element.current.ownerDocument
}
return document
}