Skip to content

Instantly share code, notes, and snippets.

@Burning-Chai
Last active September 23, 2015 11:05
Show Gist options
  • Save Burning-Chai/00974087fdd4643eb273 to your computer and use it in GitHub Desktop.
Save Burning-Chai/00974087fdd4643eb273 to your computer and use it in GitHub Desktop.
-- omission --
var request = require('superagent');
var React = require('react-native');
-- omission --
var AwesomeProject = React.createClass({
render: function() {
return (
<View style={styles.container}>
-- omission --
<Button style={styles.btn} onPress={this._getWeather}>
What Weather in Tokyo??
</Button>
<Text style={styles.instructions}>
{this.state.weather}
</Text>
</View>
);
},
_getWeather: function(event) {
var self = this;
request
.get('http://api.openweathermap.org/data/2.5/weather?q=Tokyo')
.end(function(err, res){
if (res.status == 200) {
self.setState({
weather: res.text
});
} else {
self.setState({
weather: 'ERRRO!!'
});
}
});
},
getInitialState: function() {
return {
weather: ''
}
}
});
-- omission --
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment