我看不到我在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>
);
}
}
答案 0 :(得分:0)
指定的值不同。
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>
}