开发者问题收集

元素类型无效:预期为字符串或类/函数但得到的结果为:未定义

2019-07-08
379

这是我的组件,我在文件末尾的 Home 组件中导出了 Home 。该代码在 React Native 中运行良好,但我目前正在将其移植到 expo,它停止工作了。我也读过它与导入有关,但我没有那么多。

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>
    )
  }
}

我收到此错误

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)

我导入了错误的东西吗?

Home 只是一个包装器

import React, {Component} from 'react';

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

export default Home;

错误实际上发生在播放器中,我有一个错误的导入,但它说我遇到了同样的错误,但我的 playPause 组件。在第 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
1个回答

@expo/vector-icons 默认不导出 ICON

@expo/vector-icons 默认使用 Ionicons

关于 @expo/vector-icons

在此处输入图片描述

示例

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 react-native-vector-icons 的 prop>

import Icon from 'react-native-vector-icons/dist/FontAwesome';
hong developer
2019-07-08