title: how to set state array using react hooks
body: <p>Thanks in advance.
  I have a state array as below.</p>
  
  <p>I need to add an item to state array, I came across that we need not do state mutation. How do i set state with prevState.</p>
  
  <pre><code>const [messages, setMessages] = React.useState(
          [
              {
                  _id: 12,
                  createdAt: new Date(),
                  text: 'All good',
                  user: {
                      _id: 1,
                      name: 'Sian Pol',
                  }
              },
              {
                  _id: 21,
                  createdAt: "2019-11-10 22:21",
                  text: 'Hello user',
                  user: {
                      _id: 2,
                      name: 'User New'
                  }
              }]
      )
  </code></pre>
  
  <p>How to to i call the set State to append this state array.</p>
  
  <p>Something like this?</p>
  
  <pre><code>setMessages(previousState =&gt; ({...stat
  </code></pre>
  
  <p>Can anyone help me in getting the above line code.</p>