MCPcopy Create free account
hub / github.com/adobe/react-spectrum / DOMElement

Function DOMElement

packages/react-aria-components/src/utils.tsx:469–498  ·  view source on GitHub ↗
(
  ElementType: string,
  props: DOMRenderProps<any, any> & AllHTMLAttributes<HTMLElement>,
  forwardedRef: ForwardedRef<HTMLElement>
)

Source from the content-addressed store, hash-verified

467}
468
469function DOMElement(
470 ElementType: string,
471 props: DOMRenderProps<any, any> & AllHTMLAttributes<HTMLElement>,
472 forwardedRef: ForwardedRef<HTMLElement>
473) {
474 let {render, ...otherProps} = props;
475 let elementRef = useRef<HTMLElement | null>(null);
476 let ref = useMemo(() => mergeRefs(forwardedRef, elementRef), [forwardedRef, elementRef]);
477
478 useLayoutEffect(() => {
479 if (process.env.NODE_ENV !== 'production' && render) {
480 if (!elementRef.current) {
481 console.warn(
482 'Ref was not connected to DOM element returned by custom `render` function. Did you forget to pass through or merge the `ref`?'
483 );
484 } else if (elementRef.current.localName !== ElementType) {
485 console.warn(
486 `Unexpected DOM element returned by custom \`render\` function. Expected <${ElementType}>, got <${elementRef.current.localName}>. This may break the component behavior and accessibility.`
487 );
488 }
489 }
490 }, [ElementType, render]);
491
492 let domProps: any = {...otherProps, ref};
493 if (render) {
494 return render(domProps, undefined);
495 }
496
497 return <ElementType {...domProps} />;
498}
499
500type DOMComponents = {
501 [E in keyof React.JSX.IntrinsicElements]: (

Callers

nothing calls this directly

Calls 2

mergeRefsFunction · 0.90
renderFunction · 0.50

Tested by

no test coverage detected