[v2] Warning: Each child in an array or iterator should have a unique "key" prop.
version: "react-select": "^2.0.0-beta.6" (I recently migrated from version 1.2.1, works fine in v1)
issue: FF reports: [v2] Warning: Each child in an array or iterator should have a unique "key" prop.
subsequent issue: I'm not able to select second value in isMulti mode, most likely due to above error. Selecting first value raises above error, selecting second option cause the blank value is set (the selection is reset to empty)
The code snippet (heavily simplified, the options hardcoded into callback instead of fetching from API). The ID is used as search value for API fetch.
class ProjectSelect extends React.Component {
constructor(props) {
super(props);
this.loadOptions = this.loadOptions.bind(this);
}
loadOptions(inputValue, callback) {
callback([
{
projectId: '123',
id: '1',
description: 'Project A',
},{
projectId: '456',
id: '2',
description: 'Project B'
},
]);
}
render() {
const { isLocked } = this.props;
return (
<AsyncSelect
name="Selector"
cacheOptions={false}
loadOptions={this.loadOptions}
getOptionLabel={opt => opt.description}
getOptionValue={opt => opt.projectID}
isDisabled={isLocked}
isMulti
hideSelectedOptions={false}
/>
);
}
}
I just had the same problem and looking through the source code and examples it seems like you need your data formatted as follows:
[{ value: 'ocean', label: 'Ocean' }]
The value is used as the key for each MultiValue item so it needs to be unique. The label is required too.
What might work would be:
loadOptions(inputValue, callback) {
callback([
{
value: '1',
label: 'Project A',
},{
value: '2',
label: 'Project B'
},
]);
}
I too am having this issue (using Chrome and also on version 2.0.0-beta.6). As per @jc211's comment, I'm not sure that is really the root cause of the issue. All the items in my options array are structured as objects with label and value strings (which I have verified to be unique across all options). I am using the basic (i.e., non-Async) Select component.
What's interesting is that each of the individual Select instances I'm using works fine as a standalone unit. The key error arises when I select an option from one specific Select instance on the page, at which point the other two Select instances immediately break.
Well I'm having lot of my components depended on reactSelect v1. v1 has the key/value optional and expect this in the configuration:
labelKey | string | 'label' | the option property to use for the label valueKey string | 'value' | the option property to use for the value
So in v1 I just used this:
<Select
labelKey="projectId"
valueKey="description"
now in v2 above is deprecated and been replace by function..so I changed the config to:
<AsyncSelect
getOptionLabel={opt => opt.description}
getOptionValue={opt => opt.projectID}
I'm going to take a look to source code. I believe it is just the problem in the key used in some .map method.
So in src of Select here is the key of multivalue map:
if (isMulti) {
const selectValues: Array<any> = selectValue.map(opt => {
let isFocused = opt === focusedValue;
return (
<MultiValue
{...commonProps}
components={{
Container: MultiValueContainer,
Label: MultiValueLabel,
Remove: MultiValueRemove,
}}
isFocused={isFocused}
isDisabled={isDisabled}
key={this.getOptionValue(opt)}
getOptionValue is:
getOptionValue(data: OptionType): string {
return this.props.getOptionValue(data);
}
seems there is no issue....don't understand...I will add the error screenshot and check it again tomorrow.
Nevermind... you can ignore my comment for now. It seems part of the issue is coming from our Redux store doing unexpected things.
The error from FF console:

I can confirm that once I change the options to label/value keys, the issue is gone and even multivalue select works like a charm... So the options as per jc211 works well..
I found the root cause...it is mismatch in the value key name...the
getOptionValue={opt => opt.projectID}
is supposed to have small D in the ID to respect the options projectId.
so the fix is:
getOptionValue={opt => opt.projectId}
I'd just like to add if someone in the future comes here and doesn't find these comments helpful. I had this exact 'warning' but my problem was that somewhere in the code, the options were being remapped to include just the value string.
So options were going from [{value: 'something', label: 'something'}] to ['something'].
if you are not going to use [{value: 'something', label: 'something'}]
you must specify exactly id and name data=[{_id: "5e2715b2171b6045d46ce647", name: "Laboratorio de alimentos", description: "Experto en el tema de Laboratorio de alimentos", updated_at: "2020-01-21 10:16:02", created_at: "2020-01-21 10:16:02"},{_id: "5e2715b2171b6045d46ce648", name: "Laboratorio de organicos", description: "Experto en el tema de Laboratorio de alimentos", updated_at: "2020-01-21 10:16:02", created_at: "2020-01-21 10:16:02"}]
<Select
isMulti
hideSelectedOptions={false}
name='teamIdsFilter'
menuPosition='fixed'
options={data && data}
getOptionLabel={option => ${option.name}}
getOptionValue={option => ${option._id}`}
placeholder='select'
onChange={onSelect}
/>`
` const onSelect = (optionsList) => {
setNewTemplate({ ...newTemplate, specialities: optionsList });
};`