javascript - 元素类型无效 : expected a string (for built-in components) or a class/function (for composite components) but got: object. React-Native

标签 javascript android react-native npm yarnpkg

因此,我一直在研究为什么这不起作用并且找不到任何东西。 有谁知道这个错误与什么有关?

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
    
    Check the render method of `App`.
    
    This error is located at:
        in App (created by ExpoRoot)
        in ExpoRoot
        in RCTView (created by View)
        in View (created by AppContainer)
        in RCTView (created by View)
        in View (created by AppContainer)
        in AppContainer
    - node_modules\expo\build\logs\LogSerialization.js:160:14 in _captureConsoleStackTrace
    - node_modules\expo\build\logs\LogSerialization.js:41:26 in serializeLogDataAsync
    - ... 9 more stack frames from framework internals

这是我的App.js:

import * as Icon from '@expo/vector-icons'
import * as AppLoading  from 'expo-app-loading'
import {Asset} from 'expo-asset'
import * as Font from 'expo-font'
import React from 'react'
import { StatusBar, StyleSheet, View } from 'react-native'
import AppNavigator from './navigation/AppNavigator'

export default class App extends React.Component {
  state = {
    isLoadingComplete: false,
  }

  render() {
    if (!this.state.isLoadingComplete && !this.props.skipLoadingScreen) {
      return (
        <AppLoading
          startAsync={this._loadResourcesAsync}
          onError={this._handleLoadingError}
          onFinish={this._handleFinishLoading}
        />
      )
    } else {
      return (
        <View style={styles.container}>
          <StatusBar hidden />
          <AppNavigator />
        </View>
      )
    }
  }

  _loadResourcesAsync = async () => {
    return Promise.all([
      Asset.loadAsync([
        require('./assets/images/splash.png'),
        require('./assets/images/icon.png'),
      ]),
      Font.loadAsync({
        //This is the font that we are using for our tab bar
        ...Icon.MaterialIcons.font,
        ...Icon.MaterialCommunityIcons.font,
        ...Icon.FontAwesome.font,
        ...Icon.Feather.font,
      }),
    ])
  }

  _handleLoadingError = error => {
    // In this case, you might want to report the error to your error
    // reporting service, for example Sentry
    console.warn(error)
  }

  _handleFinishLoading = () => {
    this.setState({ isLoadingComplete: true })
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
  },
})

我已经安装了所有必要的模块,重置了缓存,检查了导入语句,但似乎没有任何效果。

最佳答案

请关注展会文档:https://docs.expo.io/versions/latest/sdk/app-loading .

替换

从“expo-app-loading”导入 * 作为 AppLoading

通过

从“expo-app-loading”导入 AppLoading

解决您的问题。

关于javascript - 元素类型无效 : expected a string (for built-in components) or a class/function (for composite components) but got: object. React-Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65270658/

相关文章:

javascript - 将数据插入输入值 - AngularJS

android - 在 onRequestPermissionsResult 中,某些设备上的 grantResults 在用户拒绝权限时返回空

java - 谷歌助手是否可以在Android上按下某个应用程序中的按钮?

Android:将应用与自定义文件类型相关联

javascript - React Native 更新状态中嵌套对象的单个属性

javascript - ngSrc 在 ngIf 之前计算导致不必要的 http 请求

javascript - 我想要一个 div 自动刷新而不刷新整个页面

javascript - 向 FlatList 添加标题

javascript - 格式化饼图的工具提示

ios - React Native 应用程序在 Release模式下崩溃但在 Debug模式下运行良好