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

时间:2019-07-08 10:46:50

标签: javascript reactjs react-native expo

这是我的组件,我在文件末尾的Home组件中导出了Widget.Material.Light.TextView.ListSeparator。该代码在React Native中工作得很好,但是我目前正在将其移植到expo,并且停止工作。我也读过它与导入有关,但是我没有那么多。

Home

我遇到此错误

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)

错误实际上出在播放器中,我的导入错误,但是它说我遇到了相同的错误,只是我的playPause组件。在第13行

import React, {Component} from 'react';

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

export default Home;

1 个答案:

答案 0 :(得分:1)

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

@expo/vector-icons默认使用Ionicons

about @expo/vector-icons

enter image description here

示例

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

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