title: How to add list of objects to useState([]) in react?
body: <p>I'm trying to add [{}, {}, {} ] to useState([])</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const [messages, setMessages] = useState([]);
  const fetchMessage = (fetched_messages) =&gt; {
    if (fetched_messages) {
      setMessages([...messages, fetched_messages]);
    }
  };
  //fetched_messages = [{},{},{},{}]</code></pre>
  </div>
  </div>
  </p>
  <p>But the result was messages = [[{}, {}, {}, {}]].</p>
  <p>So I tried like this</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const [messages, setMessages] = useState([])
  
  const fetchMessage = (fetched_messages) =&gt; {
    if (fetched_messages) {
      var i
      for (i=0; i&lt;fetched_messages.length; i++) {
          setMessages([...messages, fetched_messages[i]])
      }
    }
  }</code></pre>
  </div>
  </div>
  </p>
  <p>But messages was empty.</p>
  <p>Could anyone tell me why this happened and how to fix it</p>
  <p>Thank you :)</p>