title: Updating an array in React using Hooks
body: <p>I'm trying to figure out the working of React Hook API. I'm trying to add a number to a list. The code that I commented, i.e myArray.push...
  doesn't seem to perform the operation, though the code below it is working fine. Why is it so?</p>
  
  <pre><code>import React, {useState} from 'react'
  
  export default () =&gt; {
  
    const [myArray, setArray] = useState([1,2,3])
  
    return (
      &lt;div&gt;
        {myArray.map((item=&gt;{
  
          return &lt;li&gt;{item}&lt;/li&gt;
  
        }))}
        &lt;button onClick = {()=&gt;{
  
          // myArray.push(myArray[myArray.length-1]+1)
          // setArray(myArray)
  
          setArray([...myArray, myArray[myArray.length-1]+1])
  
        }}&gt;Add&lt;/button&gt;
      &lt;/div&gt;
    )
  }
  </code></pre>