【问题标题】:NextJS Element type is invalidNextJS 元素类型无效
【发布时间】:2021-11-01 09:00:43
【问题描述】:

我在小部件文件夹中创建一个组件并将其导入我的主页(index.js)

显示错误

Error: Element type is invalid: expected a string (for built-in components) or 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.

主文件代码为

import { React, Component } from "react";
import axios from "axios";
import Style from "./widget-style/Notified.module.css";
import NotifiedModal from "../modals/NotifiedModal";

export default class GetNotified extends Component {}

【问题讨论】:

  • 你是如何导出NotifiedModal的?是默认导出还是命名导出?
  • 另外,您如何将GetNotified 组件导入index.js

标签: javascript reactjs next.js


【解决方案1】:

你必须像这样导入 React:

import React, { Component } from "react";

第一个是默认导入,第二个是命名导入。

【讨论】:

    猜你喜欢
    • 2017-05-16
    • 2019-09-01
    • 2021-08-29
    • 1970-01-01
    • 2019-07-04
    • 2018-02-07
    • 2021-05-21
    • 2021-08-05
    • 1970-01-01
    相关资源
    最近更新 更多