From 97671079ce89ab83c3ac0676722ff796e957ca7c Mon Sep 17 00:00:00 2001 From: sai6855 Date: Fri, 9 Aug 2024 12:46:20 +0530 Subject: [PATCH] move logic --- packages/mui-material/src/utils/getChildRef.js | 5 ----- packages/mui-utils/src/getReactNodeRef/getReactNodeRef.ts | 8 ++------ 2 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 packages/mui-material/src/utils/getChildRef.js diff --git a/packages/mui-material/src/utils/getChildRef.js b/packages/mui-material/src/utils/getChildRef.js deleted file mode 100644 index c24cd926d38b38..00000000000000 --- a/packages/mui-material/src/utils/getChildRef.js +++ /dev/null @@ -1,5 +0,0 @@ -export default function getChildRef(child) { - // 'ref' is passed as prop in React 19, whereas 'ref' is directly attached to children in React 18 - // below check is to ensure 'ref' is accessible in both cases - return child.props.propertyIsEnumerable('ref') ? child.props.ref : child.ref; -} diff --git a/packages/mui-utils/src/getReactNodeRef/getReactNodeRef.ts b/packages/mui-utils/src/getReactNodeRef/getReactNodeRef.ts index 6da044530bec50..e4cfe22c2a9ee3 100644 --- a/packages/mui-utils/src/getReactNodeRef/getReactNodeRef.ts +++ b/packages/mui-utils/src/getReactNodeRef/getReactNodeRef.ts @@ -8,13 +8,9 @@ import * as React from 'react'; * @returns React.Ref | null */ export default function getReactNodeRef(element: React.ReactNode): React.Ref | null { - if (!element || !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 as any).propertyIsEnumerable('ref') - ? (element.props as any).ref + return (element as any)!.props.propertyIsEnumerable('ref') + ? (element as any)!.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