Skip to content

Commit 3d9b5e7

Browse files
authored
fix: call React.isValidElement() before Children.only() (#3562)
1 parent e968a1a commit 3d9b5e7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/react/src/components/factory.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ const withAsChild = (Component: React.ElementType) => {
5353
if (!asChild) {
5454
return createElement(Component, { ...restProps, ref }, children)
5555
}
56-
57-
const onlyChild: React.ReactNode = Children.only(children)
58-
59-
if (!isValidElement<Record<string, unknown>>(onlyChild)) {
56+
57+
if (!isValidElement<Record<string, unknown>>(children)) {
6058
return null
6159
}
6260

61+
const onlyChild: React.ReactNode = Children.only(children)
62+
6363
const childRef = getRef(onlyChild)
6464

6565
return cloneElement(onlyChild, {

0 commit comments

Comments
 (0)