Guest User

Untitled

a guest
Jan 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. class App extends Component {
  2. constructor() {
  3. super();
  4. this.state = {
  5. clicked: false
  6. };
  7. }
  8.  
  9. onButtonPress() {
  10. // Will error out if "this" is not accessible
  11. this.setState({ clicked: true });
  12. }
  13.  
  14. render() {
  15. return (
  16. <View style={styles.app}>
  17. <View style={styles.header}>
  18. <Image accessibilityLabel="React logo" source={logo} resizeMode="contain" style={styles.logo} />
  19. <Text style={styles.title}>Bound Callback Demo</Text>
  20. </View>
  21. <Text style={styles.intro}>
  22. Clicked? {this.state.clicked ? 'Yes' : 'No'}
  23. </Text>
  24. <View style={{ flexDirection: 'row' }}>
  25. <Button onPress={this.onButtonPress} title="Unbound callback will error out" />
  26. <Text> </Text>
  27. <Button onPress={() => this.onButtonPress()} title="Bound callback will work" />
  28. </View>
  29. </View>
  30. );
  31. }
  32. }
Add Comment
Please, Sign In to add comment