Skip to content

Instantly share code, notes, and snippets.

@giancarlosisasi
Created May 26, 2017 02:33
Show Gist options
  • Select an option

  • Save giancarlosisasi/8012d83fcba999d1cd55393bbeeb6d74 to your computer and use it in GitHub Desktop.

Select an option

Save giancarlosisasi/8012d83fcba999d1cd55393bbeeb6d74 to your computer and use it in GitHub Desktop.
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
data: undefined,
};
}
componentWillMount() {
fetch('http://api.openweathermap.org/data/2.5/weather?q=London&APPID=f1af35f060fb74c410aa54ab5ae9d943', { method: 'GET' })
.then(response => response.json())
.then((json) => {
const data = json;
this.setState({ data });
});
}
render() {
const datos = this.state.data;
console.log('state', this.state);
return datos ?
(
<div className="App">
{
datos.weather.map(item => item.description)
}
</div>
) : (<h1>Loading</h1>)
}
}
/*React.render(
<App />,
document.getElementById('react_example')
);*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment