这是我的组件,我在文件末尾的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)


我输入的内容有误吗?

家只是包装纸

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

最佳答案

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

@expo/vector-icons默认情况下使用Ionicons

about @expo/vector-icons

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



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'} />
            }


ICONreact-native-vector-icons的道具

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

关于javascript - 元素类型无效:预期为字符串或类/函数,但得到:未定义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56933278/

10-10 14:13