Option of AutoComplete Select should not use value as a key, as value may not be unique and React requires keys to be unique
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
Version
3.8.4
Environment
Chromium 68.0.3440.75, Firefox ESR 52.9.0
Reproduction link
Steps to reproduce
Use Select
component and pass key
and value
properties to its Select.Option
s. Make sure that there are two same value
values. Notice warning about duplicate keys in the browser’s console.
What is expected?
key
property in Select.Option
component is used as component key.
What is actually happening?
value
property is being used as component key instead.
One can notice the bug while looking at https://github.com/ant-design/ant-design/blob/3.8.4/components/select/index.tsx, the Select.Option
and Select.OptGroup
components does not support key
property as one could expect after reading documentation.
export interface OptionProps {
disabled?: boolean;
value?: string | number;
title?: string;
children?: React.ReactNode;
}
export interface OptGroupProps {
label?: React.ReactNode;
}
That issue was raised before in #11074.
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
How can I add unique keys to React/MUI Autocomplete ...
You can define your own renderOption that can return the list item with a correct key value. Your code complains about the duplicated...
Read more >React Autocomplete component - Material UI - MUI
The autocomplete is a normal text input enhanced by a panel of suggested options. The widget is useful for setting the value of...
Read more >A Guide on Material UI AutoComplete in React - Refine Dev
Material UI provides a unique set of components and utilities to help ... The component's value is obtained from a predetermined range of ......
Read more >Warning: Each Child in a List Should Have a Unique 'key' Prop
If the key is an index, reordering an item in the array changes it. Then React will get confused and re-render the incorrect...
Read more >Combobox (Autocomplete) - Headless UI
Each component exposes information about its current state via render props that you can use to conditionally apply different styles or render different...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t know what component you should use but probably you need
Select[showSearch]
, you can checkout it. But still, value of AutoComplete should not be duplicated.This still appears to be a problem. I can set a key prop on
<AutoComplete.Option>
, however as soon as I set a value prop this is used as the key.I understand that value should not be duplicated, but in some cases this is not avoidable, for example when using a Belgian zip code API, where multiple towns can have the same zip code.