Blame view

天文台pc/tianwentai-ui/node_modules/@mui/utils/getReactNodeRef/getReactNodeRef.js 1.07 KB
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  "use strict";
  
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = getReactNodeRef;
  var React = _interopRequireWildcard(require("react"));
  /**
   * Returns the ref of a React node handling differences between React 19 and older versions.
   * It will return null if the node is not a valid React element.
   *
   * @param element React.ReactNode
   * @returns React.Ref<any> | null
   *
   * @deprecated Use getReactElementRef instead
   */
  function getReactNodeRef(element) {
    if (!element || ! /*#__PURE__*/React.isValidElement(element)) {
      return null;
    }
  
    // 'ref' is passed as prop in React 19, whereas 'ref' is directly attached to children in older versions
    return element.props.propertyIsEnumerable('ref') ? element.props.ref :
    // @ts-expect-error element.ref is not included in the ReactElement type
    // We cannot check for it, but isValidElement is true at this point
    // https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/70189
    element.ref;
  }