Hello, here's the problem: when I, through the API take data from the site using axios , connect this file to the component, write the result of the API request function to a new variable in state in the component, then pending Promise written there, and after a second promise it is updated and receives in [[PromiseValue]] an object with data, so how to write this object into a variable from state , and not an empty promise?
Code attached:
var axios = require('axios'); export default function getWeatherData( town ) { const SITE_URL = "http://api.openweathermap.org/data/2.5/weather"; const PRIVATE_ID = "************"; let request = `${SITE_URL}?q=${town}&APPID=${PRIVATE_ID}`; return axios.get(request) .then(r => r.data); } As well as the component code:
import React, { Component } from 'react'; import './App.css'; import getWeatherData from './api/getWeather'; class App extends Component { state = { weatherData: getWeatherData('Kiev') } componentDidMount() { console.log(this.state.weatherData) } render() { return ( <div> <h1>Hello world</h1> </div> ); } } 