Не удается увидеть, что я ввожу в TextInput - PullRequest
0 голосов
/ 21 июня 2019

Я не вижу текст, набираемый на TextInput. Текст набирается, но я не вижу его.

Я пытался использовать state и стилизовать TextInput, но все равно он не работает.

import React, {Component} from 'react';
import {View} from 'react-native';
import {Button} from './Common';

class LoginForm extends Component {

state = {text: ''}

render(){
    return(
        <View>
            <View>
                <TextInput 
                    value={this.state.text}
                    onChangeText={text => this.setState({text})}
                    style={{height: 20, width: 100}}
                    placeholder={"Can you see this?"}
                    placeholderTextColor={"red"} 
                />
            </View>

            <View>
                <Button>
                    Log In
                </Button>
            </View>
        </View>
        );
    }
}

1 Ответ

0 голосов
/ 21 июня 2019

Указанное значение отличается.

class LoginForm extends Component {

state = {text: ''}
...
    <View style={ alignItems: "center",justifyContent: "center",flex: 1}>
<TextInput 
                    value={state.text}
                    onChangeText={text => this.setState({text})}
                    placeholder={"Can you see this?"}
                    placeholderTextColor={"red"}
                    style={{height: 20, width: 100}}
                />
 </View>

}

OR

class LoginForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      text: ''
    };
  }
...


     <View style={ alignItems: "center",justifyContent: "center",flex: 1}>

                <TextInput 
                    value={this.state.text}
                    onChangeText={text => this.setState({text})}
                    style={{height: 20, width: 100}}
                />


                <Button>
                    Log In
                </Button>

        </View>

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...