Created
September 7, 2015 20:28
-
-
Save boourns/ed5e1ef4b2069365ae02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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