I have an array called company that holds multiple objects called details in mongo DB that I need to get the data from, specifically, I want to grab the company name and the employee's names from the company array and display them in a list.
My question is how do I drill in the array and render the company and employee names.
Currently in my nested map in the List component when I do details.employee, I am only able to get the result of person1 from company ABC and I need all results person 1, 2, and 3 showing from both company ABC and company EFG"
Here is the code from sandbox (note just look at List.js)
import axios from "axios";
import { useEffect, useState } from "react";
const List = () => {
const [company, setCompany] = useState([
{
details: [
{
employee: "person2",
date: "test date",
tax: "test tax",
balance: "22"
},
{
employee: "person3",
date: "test date",
tax: "test tax",
balance: "22"
}
],
company: "TEST-ABC",
_id: "60dba9fe7641a44d40364c1f",
__v: 0
},
{
details: {
employee: "person1",
date: "test date",
tax: "test tax",
balance: "22"
},
company: "TEST-EFG",
_id: "60dba9fe7641a44d40364c1f",
__v: 0
}
]);
return (
<>
<h2>Customer List</h2>
{company.map((c, i) => (
<ul key={i}>
{c.company}
{company.map((d, i) => (
<li key={i}>{d.details.employee}</li>
))}
</ul>
))}
</>
);
};
export default List;
return (
<>
<h2>Customer List</h2>
{company.map((c, i) => (
<li key={i}>
{c.company}
{company.map((d, i) => (
<li key={i}>{d.details.employee}</li>
))}
</li>
))}
</>
);
};
export default List;