本页还没有译文
本页 13 段还没译成日本語,下面显示的是英文原文。connection
还没翻译译自英文(nextjs.org)本页 13 段都还没译
The connection() function allows you to indicate rendering should wait for an incoming user request before continuing.
It's useful when a component doesn't use Request-time APIs, but you want it to be rendered at runtime and not prerendered at build time. This usually occurs when you access external information that you intentionally want to change the result of a render, such as Math.random() or new Date().
app/page.tsx
import { connection } from 'next/server'
export default async function Page() {
await connection()
// Everything below will be excluded from prerendering
const rand = Math.random()
return <span>{rand}</span>
}app/page.js
import { connection } from 'next/server'
export default async function Page() {
await connection()
// Everything below will be excluded from prerendering
const rand = Math.random()
return <span>{rand}</span>
}Reference
Type
function connection(): Promise<void>Parameters
- The function does not accept any parameters.
Returns
- The function returns a
voidPromise. It is not meant to be consumed.
Good to know
connectionreplacesunstable_noStoreto better align with the future of Next.js.- The function is only necessary when dynamic rendering is required and common Request-time APIs are not used.
Version History
| Version | Changes |
|---|---|
v15.0.0 | connection stabilized. |
v15.0.0-RC | connection introduced. |
AI 翻译查看英文原文