【问题标题】:BlueprintJS Tree add key propBlueprintJS 树添加关键道具
【发布时间】:2017-06-05 22:53:52
【问题描述】:

我正在为我的 ReactJS webapp 使用 BlueprintJS UI 组件。 我想在使用 Tree 组件呈现文件资源管理器时摆脱警告:

Each child in an array or iterator should have a unique "key" prop. Check the render method of "Tree"

documentation of the Tree component 中,我可以找到key 属性,这可能是我正在寻找的东西,但我无法消除警告。

node: [ { hasCaret: true, iconName: "folder-close", label: "Folder 0", key: '1e' } ]

Eveb 这个简单的树结构给了我警告。有什么建议吗?

【问题讨论】:

    标签: reactjs web-component blueprintjs


    【解决方案1】:

    我假设node 被传递到Tree 所需的contents 属性中。如果您查看ITreeNodeInterface,您会发现您的对象缺少许多必填字段。您必须具备以下条件:

    • depth
    • id
    • label
    • path(但如果确实需要这样做值得怀疑:请参阅ticket

    您似乎缺少depthidpath。我不确定path 是否真的需要,但对于初学者,您可以尝试将depth: 0id: 1e 添加到您的对象吗?您可能可以摆脱key,因为这是可选的。

    顺便说一句,这个警告并不是那么无害。它通常会导致神秘的 React 行为,因为它无法确定哪些组件实际上需要更新。

    【讨论】:

    • 我提供了idpathlabel,这似乎足够了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多