Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import { StyleSheet, Text, View, Button, Alert,TextInput} from 'react-native';
- export default class App extends React.Component
- {
- constructor(props)
- {
- super(props);
- this.state = {text1: 'initial'};
- }
- setVal ()
- {
- this.setState (st => {st.text1 = new Date ().toString ()});
- //this.forceUpdate ();
- }
- render()
- {
- return (
- <View style={{ alignItems: 'center', justifyContent: 'center', flex: 1}}>
- <Text style={{fontSize: 30, margin: 40}}>text1 is {this.state.text1}</Text>
- <Button
- onPress={
- () => {console.log("text1=" + this.state.text1);
- }}
- title="log data"
- color="green"
- />
- <Button
- onPress={this.setVal.bind (this)}
- title="change data"
- color="orange"
- />
- <TextInput
- style={{height: 40, width: 200, margin: 30, borderColor: 'grey', borderWidth: 2}}
- onChangeText={str => this.setState({text1: str})}
- value={this.state.text1}
- />
- </View>
- );
- }
- }
- this.setState({ text1: new Date().toString() });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement