File size: 592 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import { unstable_cache } from 'next/cache'
import { Suspense } from 'react'
const getData = unstable_cache(
async (cache) => {
const res = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random',
{ cache }
)
return res.text()
},
undefined,
{}
)
async function Data({ cache = undefined }) {
const data = await getData(cache)
return <div id="data">{data}</div>
}
export default function Page({ cache = undefined }) {
return (
<Suspense fallback={<div id="loading">Loading...</div>}>
<Data cache={cache} />
</Suspense>
)
}
|