In Dan Abramov blog post, I read
Note that the key is only relevant within a particular parent React element, such as a form. React won’t try to “match up” elements with the same keys between different parents.
So it says here:
let data = [0, 1];
return (
<div>
<div>
{data.map((x) => (
<span key={x}>{x}</span>
))}
</div>
<div>
{data.map((x) => (
<span key={x}>{x}</span> // has different parent but same keys
))}{" "}
</div>
</div>
);
React won't confuse the span elements even though they have same keys, because they belong to different parents.
But how would React differentiate, for example, such case?
let data = [0, 1];
return (
<div>
<span key={0}>0</span>
{data.map((x) => (
<span key={x}>{x}</span>
))}
{data.map((x) => (
<span key={x}>{x}</span>
))}
</div>
);
Would reconciliation work correctly in this case? How?
Because above thing would translate to something like:
<div>
<span key="0">0</span>
<span key="0">0</span>
<span key="1">1</span>
<span key="0">0</span>
<span key="1">1</span>
</div>
But I don't get any warning with above code, so seems React is able to do Reconciliation correctly still.