Skip to content

Instantly share code, notes, and snippets.

@boourns
Created September 7, 2015 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boourns/ed5e1ef4b2069365ae02 to your computer and use it in GitHub Desktop.
Save boourns/ed5e1ef4b2069365ae02 to your computer and use it in GitHub Desktop.
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
TouchableHighlight
} = React;
var Message = React.createClass({
render: function() {
return (
<Text style={this.props.style}>{this.props.message}</Text>
);
}
})
var app = React.createClass({
getInitialState: function() {
return {changed: false};
},
_onClick: function() {
console.log("called!");
this.setState({changed: true});
},
render: function() {
var msg = "initial props";
if (this.state.changed) {
msg = "Props change forced rerender";
}
return (
<View style={styles.container}>
<Message message={msg} />
<TouchableHighlight style={styles.button} onPress={this._onClick}>
<Text>Change Props</Text>
</TouchableHighlight>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
button: {
fontSize: 20,
textAlign: 'center',
margin: 10,
backgroundColor: "#1100aa",
padding: 20
},
});
AppRegistry.registerComponent('propChanger', () => app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment