title: Why is my React app not pushing all elements to an array state?
body: <p>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.</p>
  <p>This is how I'm adding users to the state:</p>
  <pre class="lang-js prettyprint-override"><code>const [customerAccounts, setCustomerAccounts] = useState([]);
  
  for(let i = 0; i &lt; res.data.customerAccounts.length; i++) {
    setCustomerAccounts([...customerAccounts, res.data.customerAccounts[i]]);
  }
  </code></pre>
  <p>When I log each index of <code>res.data.customerAccounts</code> 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?</p>