You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React.createElement类型无效错误:循环生成组件触发,换默认导出仍未解决

Fixing the "React.createElement: type is invalid" Error in Your TabWidgetComponent

Let's walk through the issues causing this error and fix them one by one:

1. Incorrect Component Import

The first critical problem is your import of TouchableWithoutFeedbackComponent — this isn't a valid component in React Native. The correct component name is TouchableWithoutFeedback. When you try to use an undefined component (because the import is wrong), React throws that "type is invalid" warning since it expects a valid component type, not undefined.

2. Invalid JSX Render Syntax

In your render method, you have this line:

{{ navigationItems }}

This wraps your navigationItems array in an extra set of curly braces, which creates a plain JavaScript object ({ navigationItems: navigationItems }). React can't render objects directly, so this will cause additional rendering issues. You only need one set of curly braces to embed the array into your JSX.

3. Verify Export/Import Matching

You mentioned switching to export default but still seeing errors — make sure your import statement matches your export style:

  • If using named export (export class TabWidgetComponent ...), import like this:
    import { TabWidgetComponent } from './path-to-your-component';
    
  • If using default export (export default class TabWidgetComponent ...), import like this:
    import TabWidgetComponent from './path-to-your-component';
    

Corrected Full Code

Here's the fixed version of your component with all the above changes:

import React from "react";
import {TabWidgetNamespace} from "shared/namespaces/tab-widget.namespaces";
import {StyleSheet, Text, TouchableWithoutFeedback, 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) => (
        <TouchableWithoutFeedback key={index}>
          <Text>{item.label}</Text>
        </TouchableWithoutFeedback>
      )
    );
    return(
      <View style={this.style.TabContainer}>
        <View style={this.style.TabNavigation}>
          {navigationItems}
        </View>
      </View>
    );
  }
}

After making these changes, the error should disappear, and your tab navigation items should render correctly.

内容的提问来源于stack exchange,提问作者Ali Batuhan Bayraktar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 22:17:39