connection
API Reference for the connection function.
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 like cookies or headers, but still needs to produce different output per request, such as Math.random() or new Date().
Examples
Synchronous database drivers
Queries from synchronous database drivers like better-sqlite3 complete during prerendering. If you are not already using Request-time APIs, call connection() before your query to exclude them from prerendering:
Now any component that calls getVisitorCount() will be excluded from prerendering, along with the rest of its output.
Reference
Type
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. |