question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Encountered two children with the same key, `.${elem}`. Child keys must be unique; when two children share a key, only the first child will be used

See original GitHub issue

发生问题的环境是:

  • antd 版本: 2.3.1
  • 操作系统及其版本: mac 10.12.1 (16B2555)
  • 浏览器及其版本: 54.0.2840.87

您做了什么?请提供尽可能详细的重现步骤。

使用Select 及 Option组件时,使用map返回的数组在DOMWrap里key不唯一,option只返回渲染了第一个

代码: <Select> { list.map(function(elem, idx) { return ( <Option key={idx} value={elem}>{elem}</Option> ); }) } </Select>

报错: Mention.js?9c0c:44 Warning: flattenChildren(…): Encountered two children with the same key, .${elem}. Child keys must be unique; when two children share a key, only the first child will be used. in ul (created by DOMWrap) in DOMWrap (created by Menu) in Menu (created by DropdownMenu) in div (created by DropdownMenu) in DropdownMenu (created by SelectTrigger) in LazyRenderBox (created by PopupInner) in div (created by PopupInner) in PopupInner (created by Popup) in Align (created by Popup) in AnimateChild (created by Animate) in Animate (created by Popup) in div (created by Popup) in Popup

您期待的结果是:

实际上的结果是:

可重现的在线演示

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
saymycommented, Nov 25, 2016

遇到同样的问题,你的<Option>如果用MAP实现时,必须有一个key键,同时,你的key的值也是你的value.

这样一个页面就能共享一个数组生成两个以上的select组件。就会报如标题的错误。

0reactions
lock[bot]commented, May 3, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Encountered Two Children with the Same Key — React Fix
Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or ...
Read more >
Encountered two children with the same key (React)
The React error "Encountered two children with the same key" occurs when two or more of the elements we return from the map()...
Read more >
React "Warning: Encountered two children with the same key"
When you render a list of components with map() , each component should have a unique key property. It is for React to...
Read more >
Encountered two children with the same key warning #310
Child keys must be unique; when two children share a key, only the first child will be used. The error does not show...
Read more >
when two children share a key, only the first child will be used
child keys must be unique; when two children share a key, only the first child will be used. You're getting a warning that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found