gpt4 book ai didi

javascript - react 键是本地的还是全局的?

转载 作者:行者123 更新时间:2023-12-05 05:18:53 25 4
gpt4 key购买 nike

阅读 this article关于使用 index 是一个 react 关键。

假设我们有两个列表:

<List1>
<el key="1" />
<el key="2" />
</List1>

<List2>
<other-el key="1" />
<other-el key="2" />
</List2>

两个列表中的元素具有相同的 key 是否安全?键是否在元素之间全局共享,或者 List1 键是第一个列表的本地键,List2 键是第二个列表的本地键?

如果列表看起来像这样会不会更好:

<List1>
<el key="1-1" />
<el key="1-2" />
</List1>

<List2>
<other-el key="2-1" />
<other-el key="2-2" />
</List2>

最佳答案

Keys Must Only Be Unique Among Siblings

Keys used within arrays should be unique among their siblings. Howeverthey don’t need to be globally unique.

来源:https://reactjs.org/docs/lists-and-keys.html#keys-must-only-be-unique-among-siblings

关于javascript - react 键是本地的还是全局的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47056881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com