title: React can't set state with hooks in useEffect()
body: <p>I'm fairly new to react and decided to develop a simple weather app.Once the page loads I want the app to ask the user for geoloacaion and then display weather data accordingly.</p>
  
  <pre><code>function App() {
    const [weather, setWeather] = useState(null);
  
    useEffect(() =&gt; {
      navigator.geolocation.getCurrentPosition(async (position) =&gt; {
        let { latitude, longitude } = position.coords;
        const data = await getWeatherByCords(latitude, longitude);
        await setWeather(data); // Line 8
        console.log(weather) //outputs undefined
        setWeather('hhello'); // Line 10
        console.log(weather) //outputs undefined
        let address = await cordsToAddress(latitude, longitude);
      });
    },[]);
  
  
    return (
      &lt;div className="App"&gt;
        &lt;h3&gt;Weather App&lt;/h3&gt;
        &lt;Weather
          data={weather.data}
        /&gt;
      &lt;/div&gt;
    );
  }
  
  export default App;
  </code></pre>
  
  <p><code>getWeatherByCords()</code> is just a helper function which sends the request to a weather api and returns its response</p>
  
  <p>I read that <code>useEffect(() =&gt; {},[])</code> hook is equal to <code>componentDidMount()</code> , and as far as I understand is should trigger only when the page is loaded or refreshed, please correct me if I'm wrong</p>
  
  <p>When I try to set <code>weather</code> do the data I received or just for a test to some string,to pass it in the <code>&lt;Weather/&gt;</code> components afterwards, it doesn't work in both cases for some reason and when I try to log <code>weather</code> in console I get undefined in both cases.</p>
  
  <p>Also should I <em>await</em> setting weather(as in line 8) or should I not(as in line 10)?</p>