File size: 1,456 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import { fetchCached, getCachedData } from './data-fetching'
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>
{children}
<section>
<h1>Layout</h1>
<p>This data is from the root layout</p>
<FetchingComponent />
<CachedFetchingComponent />
<CachedDataComponent />
</section>
</body>
</html>
)
}
async function CachedFetchingComponent() {
const data = await fetchCached(
'https://next-data-api-endpoint.vercel.app/api/random?key=cachedlayout'
)
console.log('after cached layout fetch')
return (
<dl>
<dt>
Cached Fetch
(https://next-data-api-endpoint.vercel.app/api/random?key=cachedlayout)
</dt>
<dd>{data}</dd>
</dl>
)
}
async function FetchingComponent() {
const response = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?key=uncachedlayout'
)
console.log('after uncached layout fetch')
const data = await response.text()
return (
<dl>
<dt>
Uncached Fetch
(https://next-data-api-endpoint.vercel.app/api/random?key=uncachedlayout)
</dt>
<dd>{data}</dd>
</dl>
)
}
async function CachedDataComponent() {
const data = await getCachedData('layout')
console.log('after layout cache read')
return (
<dl>
<dt>Cached Data</dt>
<dd>{data}</dd>
</dl>
)
}
|