title: spread operator within an useEffect not working
body: <p>I'm trying to update my state within the callback function of <code>socket.on</code>. I'm trying to gather all messages within an array, however, the spread operator not working, therefore, it's just updating to the last value (first element).</p>
  <p><code>console.log</code>, outputs just the updated first element. What could be the issue?</p>
  <p>Thanks</p>
  <pre><code>const [messageReceived, setMessageReceived] = useState([]);
  
      useEffect(() =&gt; {
          socket.on('receive_message', (data) =&gt; {
              console.log(data);
              setMessageReceived([...messageReceived, data.message]);
              setIsSent(false);
          });
      }, [isSent]);
  </code></pre>