Skip to content Skip to sidebar Skip to footer

Passing Keys To Children In React.js

I am running through a react tutorial on tutsplus that is a bit old, and the code doesn't work as it was originally written. I actually am totally ok with this as it forces me to l

Solution 1:

The key prop has a special meaning in React. It it is not passed to the component as prop but is used by React to aid the reconciliation of collections. If you know d3, it works similar like the key function for selection.data(). It allows React to associate the elements of the previous tree with the elements of the next tree.

It's good that you have a key (and you need one if you pass an array of elements), but if you want to pass that value along to the component, you should another prop:

<FeedItemkey={item.key}id={item.key}... />

(and access this.props.id inside the component).

Post a Comment for "Passing Keys To Children In React.js"