import { fetchCached, getCachedData } from './data-fetching'
export default function Root({ children }: { children: React.ReactNode }) {
return (
{children}
Layout
This data is from the root layout
)
}
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 (
-
Cached Fetch
(https://next-data-api-endpoint.vercel.app/api/random?key=cachedlayout)
- {data}
)
}
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 (
-
Uncached Fetch
(https://next-data-api-endpoint.vercel.app/api/random?key=uncachedlayout)
- {data}
)
}
async function CachedDataComponent() {
const data = await getCachedData('layout')
console.log('after layout cache read')
return (
- Cached Data
- {data}
)
}