gpt4 book ai didi

reactjs - 如何在 React 中导入函数组件?

转载 作者:行者123 更新时间:2023-12-04 01:01:01 24 4
gpt4 key购买 nike

我有一个想要在我的应用程序中导入的功能组件,但我得到了:

Invariant Violation 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.

检查ProjectDropContainer的渲染方法。

这是一个沙盒:

https://codesandbox.io/s/brave-voice-bdrx0

我尝试像这样导入 ProjectDropContainer:

import ProjectDropContainer from "./ProjectDropContainer";

或者像这样:

import {ProjectDropContainer} from "./ProjectDropContainer";

但还是一样!

我尝试根据(并且正在运行)的示例是:

https://codesandbox.io/s/github/emyarod/carbon/tree/dnd-uploader-codesandbox/packages/react/examples/drag-and-drop-file-uploader

最佳答案

您应该导出默认的 ProjectDropContainer 组件:

export default ProjectDropContainer

然后像这样导入它:

import ProjectDropContainer from "./ProjectDropContainer";

关于reactjs - 如何在 React 中导入函数组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58361398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com