I want to dynamically grab the ip adress from this device (since it changes overtime) and then fetch the JSON from the database by using a link in fetch: https://{ipadress}:5000/users from node.js server. But now it gives me an error Can not use keyword 'await' outside an async function. I don't know how to solve it.
The function publicIP() is where the problem is at.
async componentDidMount() {
this.drawOnCanvas();
var ipAdress = '';
publicIP()
.then(ip => {
console.log(ip);
const url = "http://" + ip + ":5000/user";
const response = await fetch(url);
const data = await response.json();
this.setState({userData: data});
console.log(this.state.userData);
// '47.122.71.234'
})
.catch(error => {
console.log(error);
// 'Unable to get IP address.'
});