title: TypeError: Cannot read properties of undefined (reading 'country')
body: <p>I'm trying to fetch data from an API and use that data in my app. But the problem is that when I try to get a certain object or data from the JSON I've just got from the API, I get a TypeError: Cannot read property 'country' of undefined.
  The property DOES exist.
  By the way, I'm using React.js.
  I really appreciate your help &amp; guidance.
  Here is the code:</p>
  <p>App.js</p>
  <pre><code>{typeof weather != 'undefined' ? (
    &lt;div&gt;
      &lt;div className=&quot;location-box&quot;&gt;
        &lt;div className=&quot;location&quot;&gt;
          
          {weather.name},{weather.sys.country} 
        &lt;/div&gt;
        &lt;div className=&quot;date&quot;&gt; {dateBuilder(new Date())} &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div className=&quot;weather-box&quot;&gt;
        &lt;div className=&quot;weather-temperature&quot;&gt;15*C&lt;/div&gt;
        &lt;div className=&quot;weather&quot;&gt;Sunny &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  ) : (&quot;NULL&quot;)}
  </code></pre>
  <p>Api from where we are going to fetched the data.</p>
  <pre class="lang-js prettyprint-override"><code>function App() {
    const [query, setQuery] = useState(&quot;&quot;);
    const [weather, setWeather] = useState({});
  
    const Search = (evt) =&gt; {
      if (evt.key === &quot;Entre&quot;) {
        debugger;
        fetch(`${api.base}weather?q=${query}&amp;units=metric&amp;APPID${api.key}`)
          .then((res) =&gt; res.json())
  
          .then((result) =&gt; {
            setWeather(result);
            setQuery(&quot;&quot;);
            console.log(result);
          });
      }
    };
  }
  </code></pre>