Answer the question
In order to leave comments, you need to log in
How to get response from axios in react-native?
I make a weather request using axios
Axios.defaults.baseURL = ' https://api.weather.yandex.ru/v1/forecast? ';
Axios.defaults.headers.common['X-Yandex-API-Key'] = 'API-KEY';
press = async () => {
const res = await Axios.get('lat=51.834464&lon=107.584574&extra=true')
.then( response => console.log(response.now_dt) )
.catch(error => console .log(error));
console log(res);
}
only undefined is output to the console
where is the error?
Answer the question
In order to leave comments, you need to log in
.then( response => console.log(response.now_dt) )
You don't return anything from the function, so further down the chain is undefined. Remove this then altogether and everything will work.
PS Mixing async/await and then/catch together for no good reason is a bit odd.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question