title: updating a useState array in a functional component in react
body: <p>I am trying to transform a class component in a functional component but I have the feeling that the useState(in a functional component) and the setState(from a class component) are not really working the same way.</p>
  <p>Here is the code in the class component that is working well:</p>
  <pre><code>// Load images
        for (var i = 1; i &lt;= imagesCount; i++) {
          const image = await tipMyMeme.methods.images(i).call()
          this.setState({
            images: [...this.state.images, image]
          })
        }
      
        this.setState({ loading: false})
  </code></pre>
  <p>And here the same code in a functional component that is not working:</p>
  <pre><code>for (var i = 1; i &lt;= imagesCount; i++) {
      const image = await tipMyMeme.methods.images(i).call()
                                      
      setImages(images =&gt; [...images, image]);
                                      
   }
  console.log(&quot;images&quot;,images)
                                 
   if (images.length==imagesCount) 
  {
      setLoading(false)  
  }
  </code></pre>
  <p>In the console.log(images), I am noticing that the array is staying empty. Is there here a real difference in the way a class and a functional component work?</p>
  <p>What I am trying to achieve is to load a list of images and send them as props in the sub component. The process of loading is working well, for exemple, if I put a console log under const image, I can see each image. What is not working I feel is the process of creating a state array of images with setImages.</p>