Something went wrong. Try again.
Something went wrong. Try again.
1.1 kB · 43 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344// SPDX-License-Identifier: AGPL-3.0-or-later
import type React from 'react';
const FORWARD_REF_TYPE = Symbol.for('react.forward_ref');const MEMO_TYPE = Symbol.for('react.memo');
interface ReactComponentType { prototype?: { isReactComponent?: boolean; };}
interface ReactMemoType { $$typeof?: symbol; type?: unknown;}
function typeSupportsRef(type: unknown): boolean { if (typeof type === 'string') { return true; } if (typeof type === 'function') { const componentType = type as ReactComponentType; return Boolean(componentType.prototype?.isReactComponent); } if (typeof type === 'object' && type !== null) { const memoType = type as ReactMemoType & Record<string, unknown>; const $$typeof = memoType.$$typeof; if ($$typeof === FORWARD_REF_TYPE) { return true; } if ($$typeof === MEMO_TYPE) { return typeSupportsRef(memoType.type); } } return false;}
export function elementSupportsRef(element: React.ReactElement | null | undefined): boolean { if (!element) return false; return typeSupportsRef(element.type);}