Welcome aboard! We are happy you are here and wish you good net-raft!
// npm install node-fetch --save
import React from 'react';
import fetch from 'node-fetch';
class App extends React.Component {
constructor() {
super();
this.state = {
data: []
}
this.setStateHandler = this.setStateHandler.bind(this);
};
setStateHandler() {
fetch('https://geoip-db.com/json')
.then(res => res.json())
.then(json => this.setState({data: json.IPv4}))
};
render() {
return (
<div>
<button onClick = {this.setStateHandler}>Click</button>
<h2>{this.state.data}</h2>
</div>
);
}
}
export default App;
The most helpful REACT solutions