React.createElement:类型无效-预期为字符串(对于内置组件)或类/函数(对于复合组件)

时间:2020-06-09 11:40:19

标签: reactjs loops for-loop native

创建for循环时遇到了该错误。

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s%s, undefined,  You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

导致错误的组件。

import React from "react";
import {TabWidgetNamespace} from "shared/namespaces/tab-widget.namespaces";
import {StyleSheet, Text, TouchableWithoutFeedbackComponent, View} from "react-native";

export class TabWidgetComponent extends React.Component<TabWidgetNamespace.TabWidgetPropsInterface, TabWidgetNamespace.TabWidgetStateInterface>{

style = StyleSheet.create({
    TabContainer: {
        overflow: 'hidden',
    },
    TabNavigation: {
        overflow: 'hidden'
    },
})

constructor(props: TabWidgetNamespace.TabWidgetPropsInterface) {
    super(props);
}

render(): React.ReactNode {

    const navigationItems = this.props.tabNavigation.map( (item, index) => (
            <TouchableWithoutFeedbackComponent key={index}>
                <Text>{item.label}</Text>
            </TouchableWithoutFeedbackComponent>
    ) );

    return(
        <View style={this.style.TabContainer}>
            <View style={this.style.TabNavigation}>
                {{ navigationItems }}
            </View>
        </View>
    );
}

}

我尝试了'导出默认类ComponentName ',但是我遇到了同样的错误。

1 个答案:

答案 0 :(得分:1)

发生错误是因为您试图在此处渲染对象-

{{ navigationItems }}

您在此处有多余的括号。应该是-

 { navigationItems }