next.js/test/e2e/app-dir/app-static/app/unstable-cache/fetch/fetch.jsx
fetch.jsx30 lines592 B
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>
  )
}
Quest for Codev2.0.0
/
SIGN IN