[英]Export default Error: The default export is not a React Component in page: "/"
I am trying to build a next app and am receiving this error.我正在尝试构建下一个应用程序并收到此错误。 Most the replies I see about this are around not using export default which I am doing!我看到的大多数回复都是围绕不使用我正在做的导出默认值!
I am basically trying to create a wrapper around my pages so that I can add things like a nav footer etc.我基本上是在尝试在我的页面周围创建一个包装器,以便我可以添加导航页脚等内容。
views/createView:视图/创建视图:
const createView: FC = (View: FC) => {
return (
<div>
<View/>
</div>
)
}
export default createView;
pages/idx页面/idx
import createView from 'views/createView';
const homePage: FC = () => {
return (
<div>hi</div>
)
}
export default createView(homePage);
The code works when I directly return the view but not if I do anything else.该代码在我直接返回视图时有效,但在我执行其他任何操作时无效。
const createView: FC = (View: FC) => View
HELP:(帮助:(
Maybe try也许试试
const createView: FC = (View: FC) => {
return (
<div>
{View}
</div>
)
}
export default createView;
Your instantiating the component and exporting it as a JSX Element, that's why you cant use it like a component because it's an instantiated value, not a function.您实例化组件并将其导出为 JSX 元素,这就是为什么您不能像组件一样使用它,因为它是实例化值,而不是 function。
Shrinidhi Hegde's answer is correct, simply changing it from <View/>
to {View}
will solve your problem (because <View/>
is attempting to create and render an element and {View}
is the act of rendering a created element.). Shrinidhi Hegde 的回答是正确的,只需将其从<View/>
更改为{View}
即可解决您的问题(因为<View/>
正在尝试创建和渲染元素,而{View}
是渲染已创建元素的行为。) .
I would strongly recommend turning your "createView" from a instantiated value to a function that creates a component as it flows nicer in React.我强烈建议将你的“createView”从一个实例化的值转换为一个 function,它可以创建一个组件,因为它在 React 中流动得更好。
The example below will allow you to continue nicely by simply turning it into a function that creates an 'FC'.下面的示例将允许您通过简单地将其转换为创建“FC”的 function 来很好地继续。
const CreateView = (View: FC): FC => () => (
<div>
<View />
</div>
);
export default CreateView;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.