title: useState variable won't get set immediately inside async function
body: <p><strong>I'm trying to set a state variable inside a function, but it doesn't get set immediately.</strong></p>
  <p>It eventually gets set, but I want to interact with the data inside the function as soon as the state is set.</p>
  <p>code:</p>
  <pre><code>  const [addresses,setAddresses] = useState&lt;any[]&gt;([]);
  
    const fetchData = async () =&gt;{
  
      try{
  
        const addresses = await fetchAddresses(data);
        setAddresses(addresses);
        console.log(addresses)
        
        //code that interacts with addresses state variable
  
      } 
      catch(err){
        console.log(err);
      }
  
    }
  
   useEffect(()=&gt;{
     if(emptyArray){
       fetchData();
     }
   },[]);
  
  </code></pre>
  <p>Any help is appreciated, thanks.</p>