Comparing version 5.41.0 to 5.42.0
@@ -13,2 +13,8 @@ import type * as React from 'react'; | ||
export declare const supportNodeRef: <T = any>(node: React.ReactNode) => node is React.ReactElement<any, string | React.JSXElementConstructor<any>> & RefAttributes<T>; | ||
/** | ||
* In React 19. `ref` is not a property from node. | ||
* But a property from `props.ref`. | ||
* To check if `props.ref` exist or fallback to `ref`. | ||
*/ | ||
export declare const getNodeRef: <T = any>(node: React.ReactNode) => React.Ref<T> | null; | ||
export {}; |
import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
import { isValidElement } from 'react'; | ||
import { isValidElement, version } from 'react'; | ||
import { ForwardRef, isFragment, isMemo } from 'react-is'; | ||
@@ -57,10 +57,28 @@ import useMemo from "./hooks/useMemo"; | ||
}; | ||
function isReactElement(node) { | ||
return /*#__PURE__*/isValidElement(node) && !isFragment(node); | ||
} | ||
export var supportNodeRef = function supportNodeRef(node) { | ||
if (! /*#__PURE__*/isValidElement(node)) { | ||
return false; | ||
return isReactElement(node) && supportRef(node); | ||
}; | ||
/** | ||
* In React 19. `ref` is not a property from node. | ||
* But a property from `props.ref`. | ||
* To check if `props.ref` exist or fallback to `ref`. | ||
*/ | ||
export var getNodeRef = Number(version.split('.')[0]) >= 19 ? | ||
// >= React 19 | ||
function (node) { | ||
if (isReactElement(node)) { | ||
return node.props.ref; | ||
} | ||
if (isFragment(node)) { | ||
return false; | ||
return null; | ||
} : | ||
// < React 19 | ||
function (node) { | ||
if (isReactElement(node)) { | ||
return node.ref; | ||
} | ||
return supportRef(node); | ||
return null; | ||
}; |
@@ -13,2 +13,8 @@ import type * as React from 'react'; | ||
export declare const supportNodeRef: <T = any>(node: React.ReactNode) => node is React.ReactElement<any, string | React.JSXElementConstructor<any>> & RefAttributes<T>; | ||
/** | ||
* In React 19. `ref` is not a property from node. | ||
* But a property from `props.ref`. | ||
* To check if `props.ref` exist or fallback to `ref`. | ||
*/ | ||
export declare const getNodeRef: <T = any>(node: React.ReactNode) => React.Ref<T> | null; | ||
export {}; |
@@ -7,3 +7,3 @@ "use strict"; | ||
}); | ||
exports.useComposeRef = exports.supportRef = exports.supportNodeRef = exports.fillRef = exports.composeRef = void 0; | ||
exports.useComposeRef = exports.supportRef = exports.supportNodeRef = exports.getNodeRef = exports.fillRef = exports.composeRef = void 0; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
@@ -65,10 +65,28 @@ var _react = require("react"); | ||
}; | ||
function isReactElement(node) { | ||
return /*#__PURE__*/(0, _react.isValidElement)(node) && !(0, _reactIs.isFragment)(node); | ||
} | ||
var supportNodeRef = exports.supportNodeRef = function supportNodeRef(node) { | ||
if (! /*#__PURE__*/(0, _react.isValidElement)(node)) { | ||
return false; | ||
return isReactElement(node) && supportRef(node); | ||
}; | ||
/** | ||
* In React 19. `ref` is not a property from node. | ||
* But a property from `props.ref`. | ||
* To check if `props.ref` exist or fallback to `ref`. | ||
*/ | ||
var getNodeRef = exports.getNodeRef = Number(_react.version.split('.')[0]) >= 19 ? | ||
// >= React 19 | ||
function (node) { | ||
if (isReactElement(node)) { | ||
return node.props.ref; | ||
} | ||
if ((0, _reactIs.isFragment)(node)) { | ||
return false; | ||
return null; | ||
} : | ||
// < React 19 | ||
function (node) { | ||
if (isReactElement(node)) { | ||
return node.ref; | ||
} | ||
return supportRef(node); | ||
return null; | ||
}; |
{ | ||
"name": "rc-util", | ||
"version": "5.41.0", | ||
"version": "5.42.0", | ||
"description": "Common Utils For React Component", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
237563
7240