警告:React.createElement:type无效 - 期望一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:undefined . 您可能忘记从其定义的文件中导出组件 . 请在AddCarScreen.js中检查您的代码:30 . ...
我一直收到这个错误,它说要在第30行检查我的代码,它是根据构造函数中给定状态的数组动态生成选择器项的行 .
样式是正确导入的,导出默认值位于不同的文件中 . 然后,此javascript文件将导出到另一个文件中的中央抽屉导航器中 .
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, Button, Picker } from 'react-native';
import styles from './StyleSheet.js';
export default class AddCarScreen extends Component {
constructor(props){
super(props)
this.state = {
carBrand : "",
carBrandList : [ 'Ford', 'VW', 'Mazda' ]
};
}
static navigationOptions = {
drawerLabel: 'Add Car',
}
render() {
const { navigate } = this.props.navigation;
return(
<View style = { styles.container }>
<Text style = { styles.screenTitle }> Add Car </Text>
<Picker
selectedValue = {this.state.carBrand}
onValueChange = {(itemValue) => this.setState({ carBrand: itemValue })}>
**{ this.state.carBrandList.map((item, index) => { return <Picker.item label = {item} value = {item} key = {index}/> } ) }**
</Picker>
<Button
onPress = {() => navigate('DrawerOpen')}
title = "Menu"
/>
</View>
);
}
};
2 回答
我认为这是香草选择器的当前错误 . 我等不及发现这个包和.map工作了 . React-native-smart-picker .
你应该改变Picker . item 到Picker . Item 正如官方文件所述:https://facebook.github.io/react-native/docs/picker.html