[英]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包中导入ActivityIndicator的,但是我不相信它会导出它。 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.