I don't know what the appropriate title for this should be, so sorry if it's not accurate.
I have a list of objects in state:
people: [
{first:'First_1', last:'Last_1', title:' Title_1', company:'Company_1'},
{first:'First_2', last:'Last_2', title:'Title_2', company:'Company_2'},
],
Currently I'm rendering each attribute into a column like this:
var first = this.state.people.map(function(person, i) {
return (
<div key={i}>
{person.first}
</div>
)
});
Same thing for last, title, etc.
And then in return:
return (
<div>
<Grid>
<Row className="show-grid">
<Col md={2}>
{first}
</Col>
<Col md={2}>
{last}
</Col>
<Col md={2}>
{title}
</Col>
<Col md={2}>
{company}
</Col>
<Col md={2}>
Recruiter Phone Screen
</Col>
</Row>
</Grid>
</div>
)
This currently works, but I have two issues:
1) I have a var first = ..., var last = ..., etc etc for each attribute.
2) if one attribute is missing, it messes everything up. IE - if First_1 doesn't have a title, Title_2 will be given to that record.
I was trying to combine everything into one variable:
var test = this.state.people.map(function(person, i) {
return {
first: function() {
return (
<div key={i}>{person.first}</div>
)
},
last: function(){
return (
<div>{person.last}</div>
)
}
}
});
And in return:
<Col md={2}>
{test.first}
</Col>
<Col md={2}>
{test.last}
</Col>
etc.
This doesn't work, but I was wondering if there was a way to make this work?