Reputation: 898
My data is structured like this currently
data = {
a2321sdrf: {
title: 'x',
content: 'asad'
},
asdasd23: {
title: 'x',
content: 'asad'
},
dfxdsfds: {
title: 'x',
content: 'asad'
}
}
Then I'm using lodash map to iterate through to output jsx. But, I can't figure out how to access the object key, to use as a key prop.
renderMenu() {
return _.map(this.props.data, item => {
return (
<h1 key={:?}>{item.title}</h1>
);
});
}
Upvotes: 0
Views: 64
Reputation: 22553
The key will be the second value to the iteritee function:
return _.map(this.props.data,
(item, key) => { return ( <h1 key={key}>{item.title}</h1> );
Upvotes: 4