Still having issues with unique key error when using object values
See original GitHub issueUsing 2.0.0, I am still getting an error when I use object values with string labels.
This is the error I get:
Warning: Encountered two children with the same key,
[object Object]. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
I created a sandbox showing the behavior here.
Just select ‘Option1’ and ‘Option 2’ and it will emit the error to the console.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:8 (1 by maintainers)
Top Results From Across the Web
React app throwing error about key, but I have already ...
1 Answer 1 · The UUIDs you are generating are indeed unique, and you are not accidentally reusing them or setting the same...
Read more >Why am I getting a primary/unique key violation? - SQL Studies
The important point to remember here is that a unique/primary key error is not always caused by inserting a row with unique column...
Read more >"Cannot insert duplicate key" error occurs when you update a ...
The duplicate key value is (0, <the value>). Note The index is not unique index and allows duplicates. Resolution. The issue was first...
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 >Error: Non-Unique value/primary key (or sql_distinct_key ...
The most common cause of this error is that your query involves a non-unique primary key. You specify a primary key by using...
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
Looks like the value should not be an object. Try to provide options like this:
{ value: "Option 1", label: "Option 1", data: new Firm({ legalName: "Option 1" }) },
And then use the data field to access your object, and value would contain some unique key. Worked in my case to get rid of these warnings.
I modified the code sandbox to better mirror my objects. There is an override of the toString method in my code that stringifies the JSON. I put a simpler version in the sandbox, but it has the same effect.
Same issue. Actually, if the code DID call toString() it would solve my problem, because the JSON-ified version would definitely be unique.
A better way might be to have a property called uniqueKey, which would be the name of a property on the object that uniquely identifies it.
<Select className="basic-single" classNamePrefix="select" isMulti={true} name="firm" options={firmOptions} uniqueKey="firmId" />
In the component’s code, the react key variable would then map to value[uniqueKey].
I’m not sure I follow you with the additional property bit. What would I add the property to?
I can see using a unique ID as the value, then using that to lookup the value when the event is called, but that is very inefficient (there are thousands of values right now, there will be many more soon).