从文档、Next.js 5.0声明和互联网上的各种文章来看,Next.js似乎很好地支持TypeScript,而且很多人都在使用它。
但是,这些线索表明,对getInitialProps应用程序至关重要的Next.js不起作用:
我怎么才能修好它?在类和函数组件中,当我执行ComponentName.getInitialProps = async function() {...}时,会得到以下错误:
[ts] Property 'getInitialProps' does not exist on type '({ data }: { data
我试图在代码中使用get getServerSideProps,但由于无法传递router.query.itmid,所以我无法这样做。
export async function getServerSideProps() {
// Call an external API endpoint to get posts.
const router = useRouter();
var id = router.query.itmid;
// You can use any data fetching library
const res = await fetch("ht
我正在使用Next.js将我的CRA转换成一个SSR应用程序。我刚刚开始,已经遇到了一个简单的问题(我希望如此)。我能够使用index.js ()将数据直接从我的getInitialProps页面呈现给浏览器。显然,我不想在索引页面上设置我的整个应用程序。
我遇到的问题是试图将数据从子组件导入索引页。使用与我的工作示例相同的代码,我得到了可怕的"TypeError:无法读取未定义的“错误的属性'map‘。这个简单的导出/导入设置在反应上是不可做的。
下面是一个类似于我的代码的例子,在子组件中.
import Link from 'next/link'
impor
我尝试将我的项目迁移到Next.js框架,以便具有服务器端渲染功能。这是我的简单页面:
class Example extends React.Component {
static getInitialProps() {
// api getting data. Need authentication data under local storage
}
render() {
return <div>{this.props.data}</div>;
}
}
我遇到的问题是:我希望我的数据首先来自getInitialProps (这就是SS
我一直在努力实现来自的一些更新。我一直在从getInitialProps转到getServerSideProps,并注意到我的exportPathMap对这些页面变得动态感到不快。运行next一切都很好,但是当我去运行next build && next export时,我遇到了一些问题。
在的docs中,它声明If your pages don't have getInitialProps you may not need next export at all; next build is already enough thanks to Automatic Stat
我一直在尝试将用户数据设置到Sentry的全局范围内,因此每次出现错误或事件时,用户信息都会传递给它。
我的应用程序是用Next.js构建的,所以我很自然地添加了配置,就像在Sentry的Next.js文档中一样。
我还不知道在哪里添加Sentry.setUser({id: user.Id})方法才能在全局范围内设置用户。
到目前为止,我已经将它添加到Sentry的_error.js文件中,在getInitialProps方法中:
import NextErrorComponent from 'next/error';
import * as Sentry from '
我使用带有next.js的样式组件,所以我的样式需要服务器端呈现,因此我如何将google分析添加到我的网站?
我检查了,但是正如我所说的,由于使用样式化的组件,我的_document文件是不同的。
// _document.js
import React from 'react'
import Document from 'next/document'
import { ServerStyleSheet } from 'styled-components'
class MyDocument extends Document {
stat
当使用NextJS构建静态站点时,我希望getInitialProps方法只在构建步骤中触发,而不是在客户机上触发。
在构建步骤中,NextJS在每个组件的呈现HTML用于生成页面的静态HTML之前运行。在客户端上,NextJS还会在呈现页面组件之前运行此方法,以便返回组件的必要支持。因此,大型请求可以延迟客户端的第一次绘制,因为这是阻塞请求。
// example usage of API call in getInitialProps
import fetch from 'isomorphic-unfetch'
function Page({ stars }) {
r