首页 > 解决方案 > 警告:遇到两个孩子使用相同的键,`-`。密钥应该是唯一的,以便组件在更新时保持其身份

问题描述

我正在运行如下代码片段:

renderPropositions() {
        const items = this.props.propositionAddress.map(async address => {
            // get the instance of deployed contract
            const instance = new web3.eth.Contract(JSON.parse(Proposition.interface), address);

            const title = await instance.methods.pTitle().call();

            return {
                header: title,
                meta: address
            }
        });

        return <Card.Group items={items} />;

    }

这不断地遇到上面的错误。但是当我删除asyncandawait函数时,没有错误。

有人可以帮忙吗?

标签: javascriptreactjsnext.jsethereum

解决方案


您收到警告是因为您的项目没有key定义,它在内部由 react 用于对账。这是 react 只更新 DOM 中实际更改的部分的方式。您应该阅读这两个主题,使用键和解

Card.Group如果您想获得有关如何删除警告的更详细的答案,您应该显示实际呈现项目的代码(在?)。


推荐阅读