【问题标题】:React native, Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined反应原生,元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义
【发布时间】:2017-08-13 09:43:39
【问题描述】:

我正在尝试构建我的第一个 react 原生应用,但我不断收到此错误:

“元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义”

我已经搜索了 anwser,但只看到了得到:“...但得到:对象”的人

下面是我的代码:

import React, { Component } from 'react';
import {
      ScrollView,
      Container,
      StyleSheet,
      Button,
      View,
      Label,
      TextInput
    } from 'react-native';

export default class Login extends Component {
  render() {
    return (
        <ScrollView style={styles.scroll}>
            <Container>
                <Button 
                    label="Forgot Login/Pass"
                    styles={{button: styles.alignRight, label: styles.label}} 
                    />
            </Container>
            <Container>
                <Label text="Username or Email" />
                <TextInput
                    style={styles.textInput}
                />
            </Container>
            <Container>
                <Label text="Password" />
                <TextInput
                    secureTextEntry={true}
                    style={styles.textInput}
                />
            </Container>
            <View style={styles.footer}>
                <Container>
                    <Button 
                        label="Sign In"
                        styles={{button: styles.primaryButton, label: styles.buttonWhiteText}} 
                        />
                </Container>
                <Container>
                    <Button 
                        label="CANCEL"
                        styles={{label: styles.buttonBlackText}} 
                        />
                </Container>
            </View>
        </ScrollView>
    );
  }
}
const styles = StyleSheet.create({
    scroll: {
        backgroundColor: '#E1D7D8',
        padding: 30,
        flexDirection: 'column'
    },
    label: {
        color: '#0d8898',
        fontSize: 20
    },
    alignRight: {
        alignSelf: 'flex-end'
    },
    textInput: {
        height: 80,
        fontSize: 30,
        backgroundColor: '#FFF'
    },
    buttonWhiteText: {
        fontSize: 20,
        color: '#FFF',
    },
    buttonBlackText: {
        fontSize: 20,
        color: '#595856'
    },
    primaryButton: {
        backgroundColor: '#34A853'
    },
    footer: {
       marginTop: 100
    }
});

有人知道问题出在哪里吗?

【问题讨论】:

    标签: android reactjs react-native


    【解决方案1】:

    问题是您要从 react-native 导入两个名为 ContainerLabel 的组件,它们不存在。

    【讨论】:

    • 我的错。没错,我是从 react 导入的,但必须使用自定义导入
    猜你喜欢
    • 2018-02-05
    • 2021-01-18
    • 2020-03-07
    • 2021-06-30
    • 2021-05-07
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 2022-06-11
    相关资源
    最近更新 更多