Skip to content

Commit 710d0dd

Browse files
authored
Merge pull request #7617 from marmelab/fix-single-field-list-key
Fix duplicate key error in SingleFieldList
2 parents 660fca6 + 95f6b09 commit 710d0dd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/ra-ui-materialui/src/list/SingleFieldList.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const SingleFieldList = (props: SingleFieldListProps) => {
7070

7171
return (
7272
<Component className={className} {...sanitizeListRestProps(rest)}>
73-
{data.map(record => {
73+
{data.map((record, rowIndex) => {
7474
const resourceLinkPath = !linkType
7575
? false
7676
: createPath({
@@ -81,7 +81,10 @@ export const SingleFieldList = (props: SingleFieldListProps) => {
8181

8282
if (resourceLinkPath) {
8383
return (
84-
<RecordContextProvider value={record} key={record.id}>
84+
<RecordContextProvider
85+
value={record}
86+
key={record.id ?? `row${rowIndex}`}
87+
>
8588
<Link
8689
className={SingleFieldListClasses.link}
8790
to={resourceLinkPath}
@@ -99,7 +102,10 @@ export const SingleFieldList = (props: SingleFieldListProps) => {
99102
}
100103

101104
return (
102-
<RecordContextProvider value={record} key={record.id}>
105+
<RecordContextProvider
106+
value={record}
107+
key={record.id ?? `row${rowIndex}`}
108+
>
103109
{children}
104110
</RecordContextProvider>
105111
);

0 commit comments

Comments
 (0)