【问题标题】:Warning: Encountered two children with the same key, `-`. Keys should be unique so that components maintain their identity across updates警告:遇到两个孩子使用相同的键,`-`。密钥应该是唯一的,以便组件在更新时保持其身份
【发布时间】:2020-04-15 07:22:17
【问题描述】:

我正在运行如下代码 sn-p:

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} />;

    }

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

有人可以帮忙吗?

【问题讨论】:

    标签: javascript reactjs next.js ethereum


    【解决方案1】:

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

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

    【讨论】:

    • 你好,渲染在Card.Group,整个渲染在render()函数中
    • Card.Group 渲染方法长什么样子?
    猜你喜欢
    • 2019-06-12
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    • 2018-10-06
    • 2021-06-24
    • 1970-01-01
    • 2017-06-01
    相关资源
    最近更新 更多