使用表单时发生错误:元素类型无效,应为字符串,但未定义 [英] Error when using a Form : Element type is invalid expected a string but got undefined
问题描述
我遇到以下错误
未捕获的不变变量:元素类型无效:预期a 字符串(对于内置组件)或类/函数(对于复合 组件),但得到:未定义.您可能忘记了导出 文件中定义的组件
Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in
我已经阅读了许多有关此错误的信息,例如此或此 但是他们都说相同:我错误地导出了我的组件.但是我不明白我的出口有什么问题
I have read many post about this error, like this or this but they all say the same : I incorrectly export my component. But I don't understand what is wrong with my export
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Image, ImageBackground, Linking, TouchableOpacity, TouchableHighlight, Alert, Button } from 'react-native';
import { createStackNavigator, createAppContainer } from "react-navigation";
import { FormLabel, FormInput, FormValidationMessage} from 'react-native-elements';
type Props = {};
export default class Login extends Component<Props> {
constructor(props) {
super(props);
state = {
login: '',
};
}
someFunction(){
Alert.alert("test")
}
onPress (){
this.props.navigation.navigate('Home')
}
checkLogin(login){
Alert.alert('test');
}
render() {
return (
<View style={styles.container}>
<Image
style={styles.image}
source={require("./images/logo.png")}>
</Image>
<FormLabel style={styles.flex1}>enter Login of your Hotel</FormLabel>
<FormInput
//value = {this.state.login}
onChangeText={login => this.checkLogin({login})}
//onChangeText={this.checkLogin.bind(login)}
placeholder='enter your login'
autoCapitalize = 'none'
/>
</View>
);
}
}
和App.js:
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Image,ImageBackground, Linking, TouchableOpacity, Alert } from 'react-native';
import { createStackNavigator, createAppContainer } from "react-navigation"
import {HomeScreen} from './HomeScreen';
import Display from './Display';
import Login from './Login';
export default class App extends React.Component {
render() {
return <AppContainer />;
}
}
const AppNavigator = createStackNavigator({
Home: HomeScreen,
Display: Display,
Login: Login,
},
{
initialRouteName: "Login",
headerMode: 'none',
}
);
const AppContainer = createAppContainer(AppNavigator);
您是否知道哪里出了问题?仅当我使用FormInput和FormLabel时才会出现错误.如果我替换为你好",则会显示
Do you have an idea of what is wrong ? Error only comes when I use FormInput and FormLabel. If I replace by hello it is displayed
推荐答案
似乎在v1.0.0-beta中不推荐使用FormInput
和FormLabel
.
It seems that FormInput
and FormLabel
were deprecated in v1.0.0-beta.
请参阅此处(在 v1.0.0-beta(测试版1)更改部分下)-
See here (under v1.0.0-beta (beta 1) Changes section) - https://github.com/react-native-training/react-native-elements/releases/tag/v1.0.0-beta
您应该将Input
而不是FormInput
与label
属性一起使用,而不是使用FormLabel
组件.
You should use Input
instead of FormInput
with a label
property instead of using FormLabel
component.
<FormInput
label={"Login"} />
这篇关于使用表单时发生错误:元素类型无效,应为字符串,但未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!