从文档,Next.js 5.0公告和互联网上的各种文章看来,Next.js很好地支持TypeScript,很多人都在使用它.
但是这些线程表明getInitialProps,这对Next.js应用程序至关重要,不起作用:
我该如何解决?在类和功能组件中,当我这样做时,ComponentName.getInitialProps = async function() {...}我收到以下错误:
[ts] Property 'getInitialProps' does not exist on type '({ data }: { data: any; }) => Element'.
Run Code Online (Sandbox Code Playgroud) 如何将道具从 Gatsby 布局传递给子级(例如 Header 组件)?
import React from "react";
export default ({ children }) => {
return <div>{children()}</div>;
};
Run Code Online (Sandbox Code Playgroud)
我发现的资源使用以下格式:
{ props.children({ ...props, foo: true }) }
{ this.props.children({...this.props, updateLayoutFunction }) }
Run Code Online (Sandbox Code Playgroud)
但由于没有props,而只有孩子,我无法让它发挥作用。我试过这个,但它也不起作用:
{ children({ foo: true }) }
Run Code Online (Sandbox Code Playgroud)
在所有情况下,我都会收到此错误: TypeError: undefined is not an object (evaluating 'history.listen')
https://github.com/gatsbyjs/gatsby/issues/3412#event-1446894145 https://github.com/gatsbyjs/gatsby/issues/2112