I have an array of objects. I would like to map this array of objects. I know how to match an array, but I can't figure out how to match an array of objects. Here is what I have done so far:
An array of objects that I want to display:
const theData = [
{
name: 'Sam',
email: 'somewhere@gmail.com'
},
{
name: 'Ash',
email: 'something@gmail.com'
}
]
My component:
class ContactData extends Component {
render() {
const renData = this.props.dataA.map((data, idx) => {
return <p key={idx}>{data}</p>
});
const renObjData = this.props.data.map(function(data, idx) {
return <p key={idx}>{data}</p>
});
return (
<div>
//works
{rennData}
<p>object</p>
//doesn't work
{renObjData}
</div>
)
}
}
ContactData.PropTypes = {
data: PropTypes.arrayOf(
PropTypes.obj
),
dataA: PropTypes.array
}
ContactData.defaultProps = {
data: theData,
dataA: dataArray
}
What am I missing?
source
share