小编luk*_*kas的帖子

使用TypeScript在Next.js中使用getInitialProps

从文档,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)

typescript definitelytyped nextjs

14
推荐指数
3
解决办法
1万
查看次数

将道具从布局传递给盖茨比中的孩子

如何将道具从 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

reactjs gatsby

6
推荐指数
1
解决办法
6506
查看次数

标签 统计

definitelytyped ×1

gatsby ×1

nextjs ×1

reactjs ×1

typescript ×1