title: Immutable state - state change not working
body: <p>I am trying to change the state of an array upon a click event. I have read up on immutability so have created a copy of the array in the method and mutated the copy rather than directly mutating the original. However the state still doesn’t update on first click. Is there something I’m doing wrong?</p>
  <pre><code>const [details, setDetails] = useState([]);
  </code></pre>
  <pre><code>  const getMovieDetails = () =&gt;{
      fetch(&quot;url&quot;)
      .then((res)=&gt; {
        return res.json();
      })
      .then((data)=&gt;{
        const newDetails =[...details];
        newDetails.push(data)
        setDetails(newDetails)
  console.log(details)
      })
    }
  </code></pre>