I am pretty new to React and I am trying to get data from my Jobly backend. In my code I set company to be the data received from my backend, and company.jobs is seen as an array of objects. However when I try to set jobs to the mapped company.jobs array, it becomes an object of objects instead, causing the error. From my understanding, company.jobs.map() should return an array of data, not an object?
This is the code extracting the data and setting jobs:
let [jobs, setJobs] = useState([]);
const company = await JoblyApi.getCompany(handle);
setJobs(jobs = company.jobs.map(j => (
<JobCard key={j.id}
title={j.title}
salary={j.salary}
equity={j.equity}/>
)));
The data JoblyApi.getCompany(handle) returns is:
{
"company": {
"handle": "anderson-arias-morrow",
"name": "Anderson, Arias and Morrow",
"description": "Somebody program how I. Face give away discussion view act inside. Your official relationship administration here.",
"numEmployees": 245,
"logoUrl": "/logos/logo3.png",
"jobs": [
{
"id": 7,
"title": "Technical brewer",
"salary": 157000,
"equity": "0"
},
{
"id": 18,
"title": "Embryologist, clinical",
"salary": 138000,
"equity": "0"
},
...(more jobs)