React-select: Warning: flattenChildren(...): Encountered two children with the same key, `.$option-...

Created on 27 Jul 2015  路  11Comments  路  Source: JedWatson/react-select

This error gets logged to the console many times over every time a user hovers over the options menu.

errors

Most helpful comment

Keying the options by index or by label fixes the issue. Is there a reason why we don't do so? If not I can make a PR.

All 11 comments

Do you have options that share the same value?

I don't. Though, should that be a problem. Would it be better to key the items by index rather than value?

Mind posting the props you're using?

Sorry, your correct I just scanned through it and found some doubles and triples: https://github.com/bezreyhan/countries/blob/master/country_calling_codes.json

Should no two items share the same value?

Keying the options by index or by label fixes the issue. Is there a reason why we don't do so? If not I can make a PR.

You can reproduce the same problem in the live demo http://jedwatson.github.io/react-select/ when adding new options to this example:

CUSTOM RENDERING FOR OPTIONS AND VALUES:

+1 I will quote @bezreyhan:

Keying the options by index or by label fixes the issue. Is there a reason why we don't do so? If not I can make a PR.

So, what are we waiting for?

+1

+1

I've run into this issue with a country dropdown - multiple labels for one value, for example United Kingdom, England and Great Britain are all the same value.

My solution was to add an ID (using uniqueId from lodash) following the value and remove it on change.

const countryOptions = countries.map(({ label, value }) => ({ label, value:${value}-${uniqueId()}}));

const onCountryChange = (value) => country.onChange(value ? value.split('-')[0] : '');

<Select options={countryOptions} {...country} onChange={onCountryChange} />

Was this page helpful?
0 / 5 - 0 ratings

Related issues

x-yuri picture x-yuri  路  3Comments

juliensnz picture juliensnz  路  3Comments

pablote picture pablote  路  3Comments

pgoldweic picture pgoldweic  路  3Comments

yrabinov picture yrabinov  路  3Comments