title: waiting for useeffect to finish and then accessing object properties
body: <p>I have the code below:</p>
  <pre><code>const [files, setFiles] = useState([]);
  const [greeting, setGreeting] = useState(0);
  const [menu, setMenu] = useState([]);
  const [options, setOptions] = useState([]);
  var customer_id = 1;
  
  useEffect(() =&gt; {
      async function getFiles() {
        
        var data = {
          &quot;customer-id&quot;: customer_id
        };
        let response = await axios.post(`http://localhost:2000/files/get-files`, data)
        //let response = await axios.post(`/files/get-files`, data)
        for (let i = 0; i &lt; response.data.length; i++) {
          setOptions(oldArray =&gt; [...oldArray, {'value': response.data[i]['id'], 'label': response.data[i]['name']}])
        }
        setFiles(response.data)
      }
      async function getIVR() {
        
          var data = {
            &quot;customer-id&quot;: customer_id
          };
          let response = await axios.post(`http://localhost:2000/files/get-ivr`, data)
          //let response = await axios.post(`/files/get-ivr`, data)
          
          setGreeting(response.data[0]['greeting'])
          setMenu(response.data[0]['menu'])
      }
  
      getFiles()
      getIVR() 
  }, []);
  var test = (options.find(x =&gt; x.value === greeting))
  console.log(test.get('label'))
  </code></pre>
  <p>The code above returns an error:</p>
  <pre><code>TypeError: Cannot read property 'get' of undefined
  </code></pre>
  <p>This is because on first render label does not exist as options is not populated yet. However, when I just console.log(test), I can see that after a few ms it is populated as shown by the logs:</p>
  <pre><code>27GreetingMenu.js:53 undefined
  GreetingMenu.js:53 undefined
  GreetingMenu.js:53 {value: 3, label: &quot;Test Menu&quot;}
  GreetingMenu.js:53 {value: 3, label: &quot;Test Menu&quot;}
  GreetingMenu.js:53 {value: 3, label: &quot;Test Menu&quot;}
  GreetingMenu.js:53 {value: 3, label: &quot;Test Menu&quot;}
  </code></pre>
  <p>How can I make it so that I can always get the value of label. This can be accomplished by somehow waiting for useeffect to finish which means options is good which means I can parse it.</p>
  <p>Let me know!</p>