Skip to content

React: Each child in a list should have a unique "key" prop

I was getting this error seemingly out of the blue, and none of the usual search results made sense: I wasn't trying to make a list. Turns out, I'd improperly passed a doubly-nested child array to React.createElement(). A la:

createElement( "div", divProps, aChild, moreChildren );

Where moreChildren was an array of nodes I'd made earlier. The fix was to remember to splat the new array:

createElement( "div", divProps, aChild, ...moreChildren );

Hooray for tired programming.

Related Posts