Skip to content

Commit dd9e1af

Browse files
committed
fix key error
1 parent ee8a014 commit dd9e1af

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/components/codeHighlights/codeHighlights.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export function makeHighlightBlocks(
1515
const items = Children.toArray(children);
1616

1717
let highlightedLineElements: ReactElement[] = [];
18-
const highlightElementGroupCounter = 0;
18+
let highlightElementGroupCounter = 0;
1919

20-
return items.reduce((arr: ChildrenItem[], child) => {
20+
return items.reduce((arr: ChildrenItem[], child, index) => {
2121
if (typeof child !== 'object') {
2222
arr.push(child);
2323
return arr;
@@ -30,7 +30,7 @@ export function makeHighlightBlocks(
3030
if (!isCodeLine) {
3131
const updatedChild = cloneElement(
3232
child as ReactElement,
33-
{},
33+
element.props,
3434
makeHighlightBlocks((child as ReactElement).props.children, language)
3535
);
3636
arr.push(updatedChild);
@@ -44,11 +44,12 @@ export function makeHighlightBlocks(
4444
} else {
4545
if (highlightedLineElements.length > 0) {
4646
arr.push(
47-
<HighlightBlock groupId={highlightElementGroupCounter} language={language}>
47+
<HighlightBlock groupId={highlightElementGroupCounter} key={highlightElementGroupCounter} language={language}>
4848
{...highlightedLineElements}
4949
</HighlightBlock>
5050
);
5151
highlightedLineElements = [];
52+
++highlightElementGroupCounter;
5253
}
5354
arr.push(child);
5455
}
@@ -98,7 +99,7 @@ export function HighlightBlock({
9899
}
99100

100101
return (
101-
<HighlightBlockContainer key={`highlight-block-${groupId}`}>
102+
<HighlightBlockContainer>
102103
<CodeLinesContainer ref={codeRef}>{children}</CodeLinesContainer>
103104
<ClipBoardContainer onClick={copyCodeOnClick} className=".clipboard">
104105
{showCopyButton && (

0 commit comments

Comments
 (0)