title: Iterating object to array useState in a loop
body: <p>I am working on React project, I have problem with dynamic component creating with <code>useState</code>;</p>
  
  <p>First, I am getting data address from Ethereum and according to this address in a <code>for</code> loop getting data from IPFS, and I want to save this data to useState array of object.</p>
  
  <p>This is function that getting address from Ethereum:</p>
  
  <pre><code>patientstorage.deployed().then(function(contractInstance){
      contractInstance.getPatientContractAddressByPatientName(usnameByte32).then(function(result){
          const PatientContract = new web3.eth.Contract(Patient.abi,result)
          PatientContract.methods.getConsultationsIpfsList().call({from: ethereum.selectedAddress}).then(function(result){
              console.log("Consul IPFSes:", result)
              for(var i=0; i&lt;result.length; i++){
                  console.log(ethers.utils.toUtf8String(result[i]))
                  IPFSREADER(result[i]);
              }
          })
      });
  })
  </code></pre>
  
  <p>and this is my <code>IPFSREADER</code> function here, getting data from IPFS and setting <code>useState</code>:</p>
  
  <pre><code>const [consul, setConsul] = useState([])
  const [count, setCount] = useState(0);
  
  function IPFSREADER(element){
      let convertedIPFSaddress = ethers.utils.toUtf8String(element)
      ipfs.cat(convertedIPFSaddress).then(function(result){
          console.log('ipfs.cat result:', result)
          let cons = result.toString('utf8')
          const parsed = JSON.parse(cons);
          console.log("cons:",parsed)
          setConsul([parsed,...consul])
          console.log("cons:",consul)
      })
  }
  </code></pre>
  
  <p><code>consul</code> is my all data which is read from IPFS storage. When i printing this like this:</p>
  
  <pre><code>&lt;Card bg="dark"&gt;
    &lt;Card.Header&gt;
      {consul.date} {consul.time}
    &lt;/Card.Header&gt;
    &lt;Card.Body&gt;
      &lt;blockquote className="blockquote mb-0"&gt;
        &lt;p&gt; Doctor:{consul.doctorName} &lt;/p&gt;
        &lt;p&gt; Address:{consul.addr} &lt;/p&gt;
        &lt;p&gt; Disease:{consul.disease} &lt;/p&gt;
        &lt;p&gt; medicine:{consul.medicine} &lt;/p&gt;
        &lt;footer className="blockquote-footer"&gt;
          Someone famous in &lt;cite title="Source Title"&gt;Source Title&lt;/cite&gt;
        &lt;/footer&gt;
      &lt;/blockquote&gt;
    &lt;/Card.Body&gt;
  &lt;/Card&gt;;
  </code></pre>
  
  <p>Now, <strong>problem</strong> is here, when i want to create a Object Array <code>useState</code>, with <code>setConsul([parsed,...consul])</code> this code in <code>IPFSREADER</code> it always return empty array, therefore, I cant use this <code>useState</code> for rendering dynamic component with <code>map</code>. Can you help me what can I do for creating the array of objects? </p>