4
How do I take a part of a JSON, put it in a variable and then throw that variable in a "Widget" of my layout?
Example: (http://ip.jsontest.com/) I want to take the value of "ip", and put in my widget instead of the value '1,410'.
constructor(props) {
super(props);
this.state = {
data:[]
}
}
componentDidMount(){
let URL = 'http://ip.jsontest.com/'
fetch(URL)
.then(function(response) {
let data = response.json()
return data;
})
.then((json) => {
console.log('parsed json', json)
data : json;
})
}
render(){
return(
<div className="container text-center">
<div className="row">
<h1> Quero que apareca o Ip aqui = {this.state.data.ip}</h1>
Instead of just
data : json;
you have to usethis.setState({data : json});
you already tested that?– Sergio
It worked with what you gave me, Thank you so much ! :D
– Henrique Hermes
Henrique: usa
this.state = {
 data: {}
 }
, with an object to be more correct, since it will be an object in the future when json arrives.– Sergio