BlueprintJS 树添加关键道具

BlueprintJS Tree add key prop

我正在为我的 ReactJS 网络应用程序使用 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 树的这个简单结构给了我警告。有什么建议吗?

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

  • depth
  • id
  • label
  • path(这是否真的需要值得怀疑:请参阅此 ticket

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

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