title: Appending array of items to array of items in React state
body: <p>I initialised state like this:</p>
  <pre><code>const [titles, setTitles] = useState([])
  </code></pre>
  <p>I'm appending another array of items <code>data.titles</code> to the array <code>titles</code> in a loop like this:</p>
  <pre><code>setTitles(titles =&gt; [...titles, data.titles])
  </code></pre>
  <p>and I have also tried this:</p>
  <pre><code>setTitles([...titles, data.titles])
  </code></pre>
  <p>but both don't seem to work, because when I'm printing <code>titles</code> in the console after the loop is done, an empty array is displayed. What am I missing here?</p>