title: React UseEffect and UseState object undefined error
body: <p>In my ClientData.js</p>
  <p>I am using useEffect to call an API(which is working), then using useState to set the API response.data to a variable(which is working).</p>
  <p>The response.data is an array of objects which I then set equal to a local variable. But when I attempt to access the object parameter I get a object undefined error.</p>
  <p>I think the problem might be is that the object is undefined due to it waiting for the API response.</p>
  <p>This is what the object from the API looks like:</p>
  <pre><code>objTest={
    ClientDatabase: &quot;21&quot;,
    ClientID: &quot;21&quot;,
    ClientName: &quot;21&quot;,
    ClientServer: &quot;21&quot;,
    Country: &quot;US - 21&quot;,
    DatabaseVersion: &quot;21&quot;,
    Namespace: &quot;21&quot;,
  };
  
  function SimpleSelect() {
      const classes = useStyles();
      
  
      const [objTest, setobjTest] = useState([]);
  
      const clientAPI =  useCallback( async() =&gt; {
         
        //returns an array of objects
             await axios({
              method:'get',
               url,
              auth: {
                  username: user,
                  password: pass
              }
          })
          .then(function(response) {
    
           
              setobjTest(  response.data)
      
        
    
        
          })
          .catch(function (error){
              console.log(error);
          });
  
      })
      useEffect( () =&gt; {
          clientAPI();
          
  
          
      }, [])
  </code></pre>
  <p>When I attempt to access the object it works using <code>console.log((objTest[0]));</code></p>
  <p>but when I attempt to access the objects parameter
  like this:  <code>console.log((objTest[0].ClientDatabase));</code></p>
  <p>it returns</p>
  <blockquote>
  <p>TypeError: Cannot read property 'ClientDatabase' of undefined</p>
  </blockquote>
  <p>This is the console log of response.data
  <a href="https://i.stack.imgur.com/s023Y.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>The response.data is an array.</p>