【问题标题】:next.js + expo: You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named importsnext.js + expo:您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入
【发布时间】:2020-08-13 00:13:31
【问题描述】:

当我尝试运行 yarn ios 时,我得到:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `MyApp`.

但是我的App.tsx,有:


class MyApp extends App {


  render() {
    const { Component, pageProps } = this.props;
    return (
      <ThemeProvider theme={theme}>
        <ScrollView>
          <Component {...pageProps} />
        </ScrollView>
        <FooterBar />
      </ThemeProvider>
    )
  }
}

export default MyApp

所以我不确定它在抱怨什么?

【问题讨论】:

  • This 可能会对您有所帮助。 Component 可能导出不正确。
  • 你能包含呈现MyApp的文件吗?
  • 我很确定是因为您需要 _app.tsx 而不是 App.tsx?请在文件顶部显示导入语句

标签: node.js reactjs expo next.js


【解决方案1】:

尝试直接从其来源导入组件,然后插入您的 pageProp。所以在例子中:

import {Component} from '../pathOfComponent';

【讨论】:

    【解决方案2】:

    您很可能没有在 this.props.Component 中传递任何内容。 Javascript 相当棘手,如果元素不存在,它会将其视为未定义

    【讨论】:

    • 我正在使用 next.js 并以某种方式处理组件。
    猜你喜欢
    • 2019-06-02
    • 1970-01-01
    • 2019-11-29
    • 2020-12-08
    • 2021-01-03
    • 1970-01-01
    • 2018-06-29
    • 2019-10-30
    • 1970-01-01
    相关资源
    最近更新 更多