mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
Similar to `getStaticProps` when draft mode is enabled we should bypass the cache so fresh data is shown. x-ref: [slack thread](https://vercel.slack.com/archives/C052BQ8F9EJ/p1687440125828479?thread_ts=1684336597.437409&cid=C052BQ8F9EJ) and [tweet](https://twitter.com/tomus_sherman/status/1669023879656873988) --------- Co-authored-by: Steven <[email protected]>
33 lines
566 B
JavaScript
33 lines
566 B
JavaScript
import { draftMode } from 'next/headers'
|
|
|
|
export default async function Page() {
|
|
const data = await fetch(
|
|
'https://next-data-api-endpoint.vercel.app/api/random'
|
|
).then((res) => res.text())
|
|
|
|
const { isEnabled } = draftMode()
|
|
|
|
return (
|
|
<main>
|
|
<pre id="draft-mode">{JSON.stringify({ isEnabled })}</pre>
|
|
<p id="data">{data}</p>
|
|
</main>
|
|
)
|
|
}
|
|
|
|
export const generateStaticParams = async () => {
|
|
const paths = [
|
|
{
|
|
route: [],
|
|
},
|
|
{
|
|
route: ['test'],
|
|
},
|
|
{
|
|
route: ['test-2'],
|
|
},
|
|
]
|
|
|
|
return paths
|
|
}
|