如何在源代码中找到有问题的行(相同的键异常)

时间:2018-01-10 23:57:42

标签: reactjs

我知道如何解决这个异常。

事情是。警告没有提到发生在哪一行/哪个文件的异常。 无论如何找到准确的根本原因?

    Warning: flattenChildren(...): Encountered two children with the same key, ``. Child keys must be unique; when two children share a key, only the first child will be used.
        in div (created by Component)
        in div (created by Component)
        in Component (created by App)
        in div (created by App)
        in div (created by App)
        in div (created by App)
        in App (created by Connect(App))
        in Connect(App)
        in Provider

1 个答案:

答案 0 :(得分:-1)

这不是一个问题,虽然我认为问题在于密钥,但在迭代中最有可能多次渲染相同的组件时,请确保它是唯一的(可以是数据中的id或任何唯一值)。

data.map((val) => <Component key={val.id} />)