简体   繁体   English

不变违规元素类型无效,应为字符串,但未定义

[英]invariant violation element type is invalid expected a string but got undefined

I have the following code which I am using on screen. 我在屏幕上使用以下代码。 I am facing following issue, 我正面临以下问题,

Invariant Violation: Element type is invalid: expected a string( for built-in components) or a class/function (for composite components) but got: object. 不变违规:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:对象。 You likely forgot to export your component from the file it's defined in. 您可能忘记了从定义文件中导出组件。

Previous screen is rendering well. 前一个屏幕呈现良好。 Even when I remove componentDidMount code and remove all view, conditional and just place <BottomNavigagtion /> It render well and I can see the results. 即使当我删除componentDidMount代码并删除所有视图时,也可以有条件地放置<BottomNavigagtion />它可以很好地呈现并且可以看到结果。

import React, { PureComponent } from "react";
import {
  StyleSheet,
  Text,
  View,
  Button,
  ScrollView,
  Image
} from "react-native";
import {
  createBottomTabNavigator,
  createAppContainer,
  createStackNavigator,
  TouchableOpacity,
  ActivityIndicator
} from "react-navigation";
import { createMaterialBottomTabNavigator } from "react-navigation-material-bottom-tabs";
import Icon from "react-native-vector-icons/Ionicons";
import { Provider } from "react-redux";
import { withNavigation } from "react-navigation";
import { createStore } from "redux";
import styles from "../styles";
import BottomNavigation from "../components/BottomNavigation";

import {
  RESOURCES_URL,
  APP_SETTINGS_URL,
  COUNTIES_URL
} from "../services/URLs";

class MoreScreen extends PureComponent {
  state = {
    // App General Settings
    app_settings: null,
    //Have a loading state where when data retrieve returns data.
    loading: true
  };
  async componentDidMount() {
    try {
      //Assign the promise unresolved first then get the data using the json method.
      // AppSettings Information

      const appSettingsApiCall = await fetch(APP_SETTINGS_URL);
      const appSettings = await appSettingsApiCall.json();

      this.setState({ app_settings: appSettings.data, loading: false });
    } catch (err) {
      console.log("Error fetching data-----------", err);
    }
  }
  render() {
    const { app_settings, loading } = this.state;
    if (!loading) {
      return (
        <ScrollView style={{ flex: 1, backgroundColor: "#f3f3f3" }}>
          <View style={styles.container}>
            <View
              style={{ flex: 1 }}
              data={app_settings}
              renderItem={this.renderItem}
            >
              <View style={styles.headerContainer}>
                <View style={styles.hamburgerContainer}>
                  <TouchableOpacity
                    style={styles.touchAbleContainer}
                    onPress={() => this.props.navigation.navigate("Welcome")}
                  >
                    <Image
                      style={styles.hamburger}
                      source={{ uri: RESOURCES_URL + "home.png" }}
                    />
                  </TouchableOpacity>
                </View>
                <View style={styles.logoContainer}>
                  <TouchableOpacity
                    style={styles.touchAbleContainer}
                    onPress={() => this.props.navigation.navigate("Welcome")}
                  >
                    <Image
                      style={styles.logo}
                      source={{ uri: RESOURCES_URL + "pinnacle-logo-blue.png" }}
                    />
                  </TouchableOpacity>
                </View>

                <BottomNavigation />
              </View>
            </View>
          </View>
        </ScrollView>
      );
    } else {
      return <ActivityIndicator />;
    }
  }
}

export default MoreScreen;

You are importing ActivityIndicator from the react-navigation package, but I don't believe it exports that. 您是从react-navigation包中导入ActivityIndi​​cator的,但是我不相信它会导出它。 It is in the 'react-native' package though: 但是,它在“ react-native”包中:

import { ActivityIndicator } from 'react-native';

The same remark for TouchableOpacity. 对TouchableOpacity的说明相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不变违规:不变违规:元素类型无效:预期为字符串(对于内置组件),但得到:未定义 - Invariant Violation: Invariant Violation: Element type is invalid: expected a string (for built-in components) but got: undefined 不变违规:元素类型无效:预期为字符串或类/函数,但得到:未定义 - Invariant Violation: Element type is invalid: expected a string or a class/function but got: undefined React-Navigation:不变违反:元素类型无效:预期为字符串,但未定义 - React-Navigation: Invariant Violation: Element type is invalid: expected a string but got undefined 不变违规:元素类型无效:应为字符串或类/函数,但得到:未定义 - Invariant Violation: Element type is invalid: expected a string , or a class/function , but got: undefined 不变违规:元素类型无效:预期是字符串或类,但得到:未定义。 检查`MyApp`的渲染方法 - Invariant Violation: Element type is invalid: expected a string or a class but got: undefined. Check the render method of `MyApp` 不变违规:元素类型无效:期望字符串(用于内置组件)或类/函数,但得到:未定义 - Invariant Violation: Element type is invalid: expected a string (for built in components) or a class/function but got: undefined 不变违规:元素类型无效,预期为字符串(对于内置组件)...但得到:未定义 - Invariant Violation: Element type is invalid expected a string (for built-in components)...but got: undefined 不变违规:元素类型无效:预期为字符串或类/函数,但得到:对象-可能发生Babel问题 - Invariant Violation: Element type is invalid: expected a string or a class/function but got: object- Possible Babel Issue 未捕获的错误:不变违规:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数但得到:object - Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object 不变违规:元素类型无效:预期为字符串或类/函数,但获得了:对象。 检查的渲染方法 - Invariant Violation: Element type is invalid: expected a string or a class/function but got: object. Check the render method of
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM