I have two ReactJS components, a page called Projects with a Table component. When I initialize the state that has Table's data like so, the Table component renders fine:
const [tableData, setTableData] = useState([{
client: "anna",
name: "no",
email: "no",
date: new Date(),
progress: 0
}])
where the Table component just runs:
<tbody>
{props.data.map((obj,index) =>
<tr onClick = {(event) => {props.updateIndex(index)}}>
<td>{obj.client}</td>
<td>{obj.name}</td>
<td>{obj.email}</td>
<td>{obj.date}</td>
<td>{obj.progress}</td>
</tr>
)}
</tbody>
However, once I attempt to overwrite this state with database data, like this, although the array of objects prints out correctly, the table cannot read the data:
const userInfo = async () => {
await Promise.all(res.data.map(async (el, index) => {
const contents = await axios.get('/api/user/'+ el.userIDS[0] + '/info');
let clientName = contents.data.firstname + ' ' + contents.data.lastname;
let email = contents.data.email;
let info = {
client: clientName,
name: el.Name,
email: email,
date: date,
progress: el.progress
};
temp.push(info)
}));
}
setTableData(temp)
userInfo();
Both times, the state array prints out nicely. This screenshot shows the state (tableData) both at initialization and after the userInfo() has been run, and the format seems to be the same:
I guess I'm just confused as to what the mistake is that I am making, since in the console both object arrays look alike, but are still off from one another. I have tried changing the structure from a 2D array to an array of objects, which I like better, but both still cause issues.