Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import React from 'react';
  2. import { StyleSheet, Text, View, Button, Alert,TextInput} from 'react-native';
  3.  
  4.  
  5. export default class App extends React.Component
  6. {
  7. constructor(props)
  8. {
  9. super(props);
  10. this.state = {text1: 'initial'};
  11. }
  12.  
  13. setVal ()
  14. {
  15. this.setState (st => {st.text1 = new Date ().toString ()});
  16. //this.forceUpdate ();
  17. }
  18.  
  19. render()
  20. {
  21. return (
  22. <View style={{ alignItems: 'center', justifyContent: 'center', flex: 1}}>
  23. <Text style={{fontSize: 30, margin: 40}}>text1 is {this.state.text1}</Text>
  24.  
  25.  
  26. <Button
  27. onPress={
  28. () => {console.log("text1=" + this.state.text1);
  29. }}
  30. title="log data"
  31. color="green"
  32. />
  33.  
  34. <Button
  35. onPress={this.setVal.bind (this)}
  36. title="change data"
  37. color="orange"
  38. />
  39.  
  40.  
  41. <TextInput
  42. style={{height: 40, width: 200, margin: 30, borderColor: 'grey', borderWidth: 2}}
  43. onChangeText={str => this.setState({text1: str})}
  44. value={this.state.text1}
  45. />
  46. </View>
  47. );
  48. }
  49. }
  50.  
  51. this.setState({ text1: new Date().toString() });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement