简体   繁体   English

元素类型无效:应为字符串或类/函数,但得到:未定义

[英]Element type is invalid: expected a string or a class/function but got: undefined

Here is my component, I exported Home in my Home component at the end of the file.这是我的组件,我在文件末尾的 Home 组件中导出了Home The code worked just fine in React Native but I'm currently porting it to expo and it stopped working.该代码在 React Native 中运行良好,但我目前正在将其移植到 expo 并且它停止工作。 I have read also it has something to do with the imports but I don't have that many.我也读过它与进口有关,但我没有那么多。

import React, { Component } from 'react';
import { Text, View } from 'react-native';

import Home from './src/views/containers/home'
import Header from './src/sections/components/header'
import SuggestionList from './src/videos/containers/suggestion-list'
import CategoryList from './src/videos/containers/category-list'
import Player from './src/player/containers/player'

import API from './utils/api'
export default class App extends Component<{}> {
  state = {
    suggestionList: [],
    categoryList: []
  }

  async componentDidMount() {
    //some code
  }
  render() {
    return (
      <Home> //Line 28
        <Header/>
        <Player/>
        <Text>Search</Text>
        <Text>Categories</Text>
        <CategoryList 
          list={this.state.categoryList}
        />
        <SuggestionList 
          list={this.state.suggestionList}
        />

      </Home>
    )
  }
}

I'm getting this error我收到这个错误

Check the render method of `App`.

This error is located at:
in Home (at App.js:28)
in App (at withExpoRoot.js:20)
in RootErrorBoundary (at withExpoRoot.js:19)
in ExpoRootComponent (at renderApplication.js:35)
in RCTView (at View.js:45)
in View (at AppContainer.js:98)
in RCTView (at View.js:45)
in View (at AppContainer.js:115)
in AppContainer (at renderApplication.js:34)

Am I importing something wrong?我导入的东西有问题吗?

Home is just a wrapper家只是一个包装

import React, {Component} from 'react';

class Home extends Component {
    render(){
        return this.props.children
    }
}

export default Home;

The error was actually in the player, where I had a bad import but then it says that I got the same error but for my playPause component.错误实际上是在播放器中,我在其中导入了错误,但随后它说我遇到了相同的错误,但对于我的 playPause 组件。 In line 13在第 13 行

import React from 'react'
import {
    TouchableHighlight,
    StyleSheet,
    Platform,
} from 'react-native'

import Icon from '@expo/vector-icons'

function PlayPause(props) {
    return (

        <TouchableHighlight //line 13
            onPress={props.onPress}
            style={styles.container}
            underlayColor='rgba(255,255,255,.3)'
            hitSlop={{
                left: 5,
                top: 5,
                bottom: 5,
                right: 5
            }}
        >
            {
                props.isPaused ? <Icon size={20} color="#98ca3f" name={
                    Platform.OS === 'ios' ? 'ios-play' : 'md-play'
                  } /> : <Icon size={20} color="#98ca3f" name={
                    Platform.OS === 'ios' ? 'ios-pause' : 'md-pause'} />
            }
        </TouchableHighlight>
    )
}

export default PlayPause

@expo/vector-icons does not default export ICON . @expo/vector-icons不默认导出ICON

@expo/vector-icons uses Ionicons by default. @expo/vector-icons默认使用Ionicons

about @expo/vector-icons关于@expo/vector-icons

在此处输入图片说明

example例子

import { Ionicons } from '@expo/vector-icons';
...
  {
                props.isPaused ? <Ionicons size={20} color="#98ca3f" name={
                    Platform.OS === 'ios' ? 'ios-play' : 'md-play'
                  } /> : <Ionicons size={20} color="#98ca3f" name={
                    Platform.OS === 'ios' ? 'ios-pause' : 'md-pause'} />
            }

ICON is the prop of react-native-vector-icons ICONreact-native-vector-icons的支柱

import Icon from 'react-native-vector-icons/dist/FontAwesome';

暂无
暂无

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

相关问题 更新我得到的所有依赖项:元素类型无效:预期为字符串或类/函数(对于复合组件)但得到:未定义 - Updating all dependencies I got: Element type is invalid: expected a string or a class/function (for composite components) but got: undefined 元素类型无效:期望的字符串或类但未定义 - Element type is invalid: expected string or class but got undefined React Native - “元素类型无效:需要字符串或类/函数但未定义” - 导入自定义库? - React Native - “Element type is invalid: expected a string or a class/function but got undefined” - importing custom library? 简单的 react-spring 组件在 gatsby 中不起作用 - 元素类型无效:预期为字符串或类/函数但得到:未定义 - Simple react-spring component not working in gatsby - Element type is invalid: expected a string or a class/function but got: undefined NextJS:元素类型无效:期望字符串(用于内置组件)或类/函数(用于复合组件)但得到:未定义 - NextJS: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 元素类型无效:预期字符串(用于内置组件)或类/函数(用于复合组件)但得到:未定义 - Element type is invalid: expected string (for built-in components) or a class/function (for composite components) but got: undefined 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 如何修复错误:元素类型无效:需要字符串或类/函数但得到:未定义? - How to fix Error: Element type is invalid: expected a string or a class/function but got: undefined? 渲染错误元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义 - Render Error Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 未捕获的错误:元素类型无效:预期为字符串(内置组件)或类/函数(复合组件),但得到:未定义 - Uncaught Error: Element type is invalid: expected a string (built-in components) or a class/function ( composite components) but got: undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM