Answer the question
In order to leave comments, you need to log in
Passing an array of objects to component?
Good morning! Need help! I have an array of objects
import React from 'react';
import JobsList from './JobsList';
const jobs = [
{
id: 1,
name: 'John',
work: 'Taxi'
},
{
id: 2,
name: 'Alex',
work: 'Doctor'
}
];
export default () => <JobsList Jobs={jobs} />;
import React, { Component } from 'react';
import Jobs from './JobsListContainer';
class JobsList extends Component {
render(){
const { Jobs } = this.props;
console.log(Jobs);
return(
<div>
{Jobs.map(e => (
<ul key={e.id}>
<li>{e.name}</li>
<li>{e.work}</li>
</ul>
))}
</div>
);
}
}
export default JobsList;
import React, { Component } from 'react';
import JobsList from './components/JobsList';
class App extends Component {
render() {
return (
<div>
<JobsList />
</div>
);
}
}
export default App;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question