Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumReactrecursion in componentsSingle-choice MCQ

You render a recursive tree where each node may be expanded. A node's expanded state is stored in a Set in the parent and read by index path. Reordering siblings causes some nodes to show the wrong expanded state, and React warns about keys. The current key is the array index. What is the root cause?

{nodes.map((node, i) => ( <TreeNode key={i} node={node} path={`${parentPath}.${i}`} /> ))}