Skip to content

Commit 7cf0b55

Browse files
committed
[material-ui][Autocomplete] Fix React 18.3 key spread warnings in Autocomplete demos (#42691)
1 parent e5e9b9d commit 7cf0b55

File tree

4 files changed

+70
-46
lines changed

4 files changed

+70
-46
lines changed

docs/data/material/components/autocomplete/FixedTags.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ export default function FixedTags() {
2121
options={top100Films}
2222
getOptionLabel={(option) => option.title}
2323
renderTags={(tagValue, getTagProps) =>
24-
tagValue.map((option, index) => (
25-
<Chip
26-
label={option.title}
27-
{...getTagProps({ index })}
28-
disabled={fixedOptions.indexOf(option) !== -1}
29-
/>
30-
))
24+
tagValue.map((option, index) => {
25+
const { key, ...tagProps } = getTagProps({ index });
26+
return (
27+
<Chip
28+
key={key}
29+
label={option.title}
30+
{...tagProps}
31+
disabled={fixedOptions.indexOf(option) !== -1}
32+
/>
33+
);
34+
})
3135
}
3236
style={{ width: 500 }}
3337
renderInput={(params) => (

docs/data/material/components/autocomplete/FixedTags.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ export default function FixedTags() {
2121
options={top100Films}
2222
getOptionLabel={(option) => option.title}
2323
renderTags={(tagValue, getTagProps) =>
24-
tagValue.map((option, index) => (
25-
<Chip
26-
label={option.title}
27-
{...getTagProps({ index })}
28-
disabled={fixedOptions.indexOf(option) !== -1}
29-
/>
30-
))
24+
tagValue.map((option, index) => {
25+
const { key, ...tagProps } = getTagProps({ index });
26+
return (
27+
<Chip
28+
key={key}
29+
label={option.title}
30+
{...tagProps}
31+
disabled={fixedOptions.indexOf(option) !== -1}
32+
/>
33+
);
34+
})
3135
}
3236
style={{ width: 500 }}
3337
renderInput={(params) => (

docs/data/material/components/autocomplete/Sizes.js

+24-16
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ export default function Sizes() {
6666
getOptionLabel={(option) => option.title}
6767
defaultValue={top100Films[13]}
6868
renderTags={(value, getTagProps) =>
69-
value.map((option, index) => (
70-
<Chip
71-
variant="outlined"
72-
label={option.title}
73-
size="small"
74-
{...getTagProps({ index })}
75-
/>
76-
))
69+
value.map((option, index) => {
70+
const { key, ...tagProps } = getTagProps({ index });
71+
return (
72+
<Chip
73+
key={key}
74+
variant="outlined"
75+
label={option.title}
76+
size="small"
77+
{...tagProps}
78+
/>
79+
);
80+
})
7781
}
7882
renderInput={(params) => (
7983
<TextField
@@ -92,14 +96,18 @@ export default function Sizes() {
9296
getOptionLabel={(option) => option.title}
9397
defaultValue={[top100Films[13]]}
9498
renderTags={(value, getTagProps) =>
95-
value.map((option, index) => (
96-
<Chip
97-
variant="outlined"
98-
label={option.title}
99-
size="small"
100-
{...getTagProps({ index })}
101-
/>
102-
))
99+
value.map((option, index) => {
100+
const { key, ...tagProps } = getTagProps({ index });
101+
return (
102+
<Chip
103+
key={key}
104+
variant="outlined"
105+
label={option.title}
106+
size="small"
107+
{...tagProps}
108+
/>
109+
);
110+
})
103111
}
104112
renderInput={(params) => (
105113
<TextField

docs/data/material/components/autocomplete/Sizes.tsx

+24-16
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ export default function Sizes() {
6666
getOptionLabel={(option) => option.title}
6767
defaultValue={top100Films[13]}
6868
renderTags={(value, getTagProps) =>
69-
value.map((option, index) => (
70-
<Chip
71-
variant="outlined"
72-
label={option.title}
73-
size="small"
74-
{...getTagProps({ index })}
75-
/>
76-
))
69+
value.map((option, index) => {
70+
const { key, ...tagProps } = getTagProps({ index });
71+
return (
72+
<Chip
73+
key={key}
74+
variant="outlined"
75+
label={option.title}
76+
size="small"
77+
{...tagProps}
78+
/>
79+
);
80+
})
7781
}
7882
renderInput={(params) => (
7983
<TextField
@@ -92,14 +96,18 @@ export default function Sizes() {
9296
getOptionLabel={(option) => option.title}
9397
defaultValue={[top100Films[13]]}
9498
renderTags={(value, getTagProps) =>
95-
value.map((option, index) => (
96-
<Chip
97-
variant="outlined"
98-
label={option.title}
99-
size="small"
100-
{...getTagProps({ index })}
101-
/>
102-
))
99+
value.map((option, index) => {
100+
const { key, ...tagProps } = getTagProps({ index });
101+
return (
102+
<Chip
103+
key={key}
104+
variant="outlined"
105+
label={option.title}
106+
size="small"
107+
{...tagProps}
108+
/>
109+
);
110+
})
103111
}
104112
renderInput={(params) => (
105113
<TextField

0 commit comments

Comments
 (0)