我有一個警告說失敗道具類型:無效的道具價值「鍵盤類型」 - ReactNative
Warning: Failed prop type: Invalid prop 'keyboardType' of value "supplied to 'TextInput' expected one of ["default", "email-address", etc]
我所試圖做的是改變基礎上,選擇dropdown
的keyboardType
。
工作正常,但我還是不斷有此錯誤。我不知道我做錯了什麼。我對React和ReactNative仍然很陌生,如果有人能夠幫助我解釋事情的工作方式,並給我舉例說明如何去做,那將會非常感激。
這裏是我的代碼
import ModalDropdown from 'react-native-modal-dropdown';
const types = ['Phone', 'Email Address', 'Name', 'Address'];
export default class SampleComponent extends Component{
constructor(props) {
super(props);
this.state = {
dataInput: '',
typeOfKeyboard: '',
};
}
// this is how I set the state to be inputed in my `keyboardType` props
typeSelectedOnSelect(id, value) {
if(value== 'Phone'){
this.setState({typeOfKeyboard: 'numeric'});
}else if(value== 'Email Address'){
this.setState({typeOfKeyboard: 'email-address'});
}else{
this.setState({typeOfKeyboard: 'default'});
}
}
render(){
<View style={{flexDirection: 'column', flex: 1, padding: 20}}>
<Text style={styles.contactTypeText}>Contact Type</Text>
<ModalDropdown
options={types}
onSelect={this.contactTypeOnSelect.bind(this)}
style={styles.dropdownContainer}
dropdownStyle={styles.dropdownStyle}
textStyle= {styles.dropdownText}
/>
<TextInput label="Type anything" keyboardType={this.state.typeOfKeyboard} onChangeText={(dataInput)=>this.setState({dataInput})} value={this.state.dataInput} />
</View>
感謝您的幫助!
謝謝你清除它向我走來。我不再收到警告。 – natsumiyu
太棒了:)。很高興我能幫上忙! – WilomGfx