A
A
albertalexandrov2018-11-06 21:40:11
React
albertalexandrov, 2018-11-06 21:40:11

Returning a variable from axios.get?

Hello everyone!)
There is a code https://codepen.io/anon/pen/xQwVdZ . Now at the first click ip is not displayed in the console. Only at the second. How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-11-06
@albertalexandrov

getMyIP() {    
  return axios.get('https://httpbin.org/get').then(response => response.data.origin)
}
  
handleClick() {
  this.getMyIP().then(ip => console.log(`ip: ${ip}`))
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question