I am trying to fetch data from another fetched data by id, then display them together in a card using react hooks. I am getting an empty array error in the console. Any help would be greatly appreciated. Also not sure if I am storing the data correclty in state.
const CardContainer = () => {
const [work, setWork] = useState([]);
const [work2, setWork2] = useState([]);
useEffect(() => {
fetch("https://www.hatchways.io/api/assessment/work_orders")
.then((response) => response.json())
.then((data) => {
console.log(data.orders);
data.orders.map((order) => {
console.log(order.workerId);
fetch(
`https://www.hatchways.io/api/assessment/workers/${order.workerId}`
)
.then((res) => res)
.then((data) => setWork2(data));
});
});
}, []);
console.log(work);
return (
<div>
<h2>Cards</h2>
{work.map((items, index) => (
<CardUI key={index} props={items} />
))}
</div>
);
};