I have a table that maps through a state that is set to an array of users. The users are retrieved from a server and database, however, I'm only getting one user added to the state when there are two total.
This is how I'm adding users to the state:
const [customerAccounts, setCustomerAccounts] = useState([]);
for(let i = 0; i < res.data.customerAccounts.length; i++) {
setCustomerAccounts([...customerAccounts, res.data.customerAccounts[i]]);
}
When I log each index of res.data.customerAccounts
I get both accounts logged, but only one is displayed in the table, and when I log the state with a button I also only see one, and it's always the second one (index 1, not 0). What could be the reason for this?