Skip to content

Commit

Permalink
feat: preserve original keys of children elements
Browse files Browse the repository at this point in the history
  • Loading branch information
metacode22 committed Sep 1, 2024
1 parent fa3e052 commit 67851af
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/react/react/src/components/Separated/Separated.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @tossdocs-ignore */
/** @jsxImportSource react */
import { Children, Fragment, PropsWithChildren, ReactNode } from 'react';
import { Children, Fragment, isValidElement, PropsWithChildren, ReactNode } from 'react';

interface Props extends PropsWithChildren {
with: ReactNode;
Expand All @@ -15,10 +15,10 @@ export function Separated({ children, with: separator, first = false, last = fal
return (
<>
{first && separator}
{childrenArray.map((child, i) => (
<Fragment key={i}>
{childrenArray.map((child, index) => (
<Fragment key={isValidElement(child) ? child.key : index}>
{child}
{i + 1 !== childrenLength ? separator : null}
{index + 1 !== childrenLength && separator}
</Fragment>
))}
{last && separator}
Expand Down

0 comments on commit 67851af

Please sign in to comment.