Advertisement
amigojapan

Untitled

Mar 1st, 2022
1,134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react'
  2. import {
  3.    Text,
  4.    Button,
  5.    View,
  6.    TextInput
  7. } from 'react-native'
  8.  
  9. export default class reactApp extends Component {
  10.    constructor() {
  11.       super()
  12.       this.state = {
  13.          myText: '\n\n\nenter your name, then press ok',
  14.          name:""
  15.       }
  16.    }
  17.    
  18.    updateText = () => {
  19.       this.setState({myText: '\n\n\nHello '+this.state.name+"!"})
  20.    }
  21.    //updateName = () => {
  22.    //   this.setState({name: n})
  23.    //}  
  24.    render() {
  25.       return (
  26.          <View>
  27.             <Text onPress = {this.updateText}>
  28.                {this.state.myText}
  29.             </Text>
  30.             <View
  31.             style={{borderWidth : 5}}
  32.             >
  33.             <TextInput
  34.               onChangeText={(textvalue) => this.setState({name:textvalue})}
  35.               value={this.state.name}
  36.             >
  37.             </TextInput>
  38.             </View>
  39.             <Button
  40.             title="ok"
  41.             onPress={
  42.               this.updateText
  43.             }
  44.             ></Button>
  45.          </View>
  46.       );
  47.    }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement