我在使用 NextJS 时遇到此错误。
Server Error
Error: 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.
This error happened while generating the page. Any console logs will be displayed
in the terminal window.
来源:
pages\_document.tsx (86:33) @ Function.getInitialProps
84 | }
85 |
> 86 | const { html, head } = await ctx.renderPage({ enhanceApp })
| ^
87 | const styles = [...flush()]
88 | return { html, head, styles }
89 | }
我的代码:
function MyApp({ Component, pageProps, openSidebar, closeSidebar }) {
const [sidebarOpen, setSidebarOpen] = useState(false)
useEffect(() => {
const openSidebar = () => {
setSidebarOpen(true);
};
const closeSidebar = () => {
setSidebarOpen(false);
};
})
return (
<>
<NavBar sidebarOpen={sidebarOpen} openSidebar={openSidebar} />
<Container>
<Component {...pageProps} />
<Main />
<SideBar sidebarOpen={sidebarOpen} closeSidebar={closeSidebar} />
</Container>
</>
)
}
export default MyApp