Skip to content

Commit 2c9931f

Browse files
committed
feat(ui-react-utils): safeClonElement to support react 19
1 parent d111d95 commit 2c9931f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/ui-react-utils/src/safeCloneElement.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ function safeCloneElement<
6060
...children: ReactNode[]
6161
) {
6262
const cloneRef = props.ref
63-
const originalRef = element.ref
63+
// Support both React 18 (element.ref) and React 19+ (element.props.ref)
64+
// TypeScript's ReactElement type does not always include a 'ref' property,
65+
// so we use 'as any' to safely access it for React 18 compatibility.
66+
const originalRef =
67+
element.props && element.props.ref !== undefined
68+
? element.props.ref
69+
: (element as any).ref
6470
const originalRefIsAFunction = typeof originalRef === 'function'
6571
const cloneRefIsFunction = typeof cloneRef === 'function'
6672

0 commit comments

Comments
 (0)