Blame view

天文台pc/tianwentai-ui/node_modules/@mui/utils/esm/getReactElementRef/getReactElementRef.js 716 Bytes
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  import * as React from 'react';
  
  /**
   * Returns the ref of a React element handling differences between React 19 and older versions.
   * It will throw runtime error if the element is not a valid React element.
   *
   * @param element React.ReactElement
   * @returns React.Ref<any> | null
   */
  export default function getReactElementRef(element) {
    // 'ref' is passed as prop in React 19, whereas 'ref' is directly attached to children in older versions
    if (parseInt(React.version, 10) >= 19) {
      return element?.props?.ref || null;
    }
    // @ts-expect-error element.ref is not included in the ReactElement type
    // https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/70189
    return element?.ref || null;
  }