使用表单时发生错误:元素类型无效,应为字符串,但未定义

时间:2019-04-09 15:00:15

标签: react-native react-native-elements

我遇到以下错误

  

未捕获的不变变量:元素类型无效:预期a   字符串(对于内置组件)或类/函数(对于复合   组件),但得到:未定义。您可能忘记了导出   定义在文件中的组件

我已经阅读了很多有关此错误的信息,例如thisthis 但是他们都说相同:我错误地导出了我的组件。但是我不明白我的出口有什么问题

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时才会出现错误。如果我替换为“你好”,则会显示

1 个答案:

答案 0 :(得分:0)

v1.0.0-beta中似乎已弃用FormInputFormLabel

请参见此处(在 v1.0.0-beta(测试版1)更改部分下)-https://github.com/react-native-training/react-native-elements/releases/tag/v1.0.0-beta

您应将Input而不是FormInputlabel属性一起使用,而不要使用FormLabel组件。

<FormInput 
   label={"Login"} />