Skip to content

Commit 5e7831f

Browse files
fix: check if separator is a valid React element (#10199)
* fix: check if `separator` is a valid React element * docs: update --------- Co-authored-by: Segun Adebayo <joseshegs@gmail.com>
1 parent d1f6cc1 commit 5e7831f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.changeset/four-meals-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@chakra-ui/react": patch
3+
---
4+
5+
fix: check if `separator` is a valid React element

packages/react/src/components/stack/stack.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ export const Stack = forwardRef<HTMLDivElement, StackProps>(
8484
)
8585

8686
const clones = useMemo(() => {
87-
if (!separator) return children
87+
if (!isValidElement(separator)) return children
8888
return getValidChildren(children).map((child, index, arr) => {
8989
const key = typeof child.key !== "undefined" ? child.key : index
90-
const sep = cloneElement(separator, {
91-
css: [separatorStyle, separator.props.css],
90+
const typedSep = separator as React.ReactElement<any>
91+
const sep = cloneElement(typedSep, {
92+
css: [separatorStyle, typedSep.props.css],
9293
})
9394
return (
9495
<Fragment key={key}>

0 commit comments

Comments
 (0)