Skip to content

Commit

Permalink
docs: fix data fetching with ORM (vercel#69702)
Browse files Browse the repository at this point in the history
Follow up from vercel#69695.
  • Loading branch information
leerob committed Sep 5, 2024
1 parent 7198111 commit 63e0298
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default async function Page() {
}
```

If you are not using any [dynamic functions](/docs/app/building-your-application/rendering/server-components#dynamic-rendering) anywhere else in your application, this page will be prerendered during `next build` to a static page. The data can then be updated using [Incremental Static Regeneration](/docs/app/building-your-application/data-fetching/incremental-static-regeneration).
If you are not using any [dynamic functions](/docs/app/building-your-application/rendering/server-components#dynamic-rendering) anywhere else in this route, it will be prerendered during `next build` to a static page. The data can then be updated using [Incremental Static Regeneration](/docs/app/building-your-application/data-fetching/incremental-static-regeneration).

If you do _not_ want to cache the response from `fetch`, you can do the following:

Expand All @@ -97,7 +97,7 @@ let data = await fetch('https://api.vercel.app/blog', { cache: 'no-store' })

### Fetching data on the server with an ORM or database

This page will be SSG by default. The page will be prerendered during `next build`. It can be revalidated using [Incremental Static Regeneration](/docs/app/building-your-application/data-fetching/incremental-static-regeneration).
This component will fetch and display a list of blog posts. The response from the database will be cached.

```tsx filename="app/page.tsx" switcher
import { db, posts } from '@/lib/db'
Expand Down Expand Up @@ -129,7 +129,15 @@ export default async function Page() {
}
```

The database call will run again every time you revalidate the page using [Incremental Static Regeneration](/docs/app/building-your-application/data-fetching/incremental-static-regeneration).
If you are not using any [dynamic functions](/docs/app/building-your-application/rendering/server-components#dynamic-rendering) anywhere else in this route, it will be prerendered during `next build` to a static page. The data can then be updated using [Incremental Static Regeneration](/docs/app/building-your-application/data-fetching/incremental-static-regeneration).

If you do _not_ want to cache the response from the database, you can add the following to your file:

```js
export const dynamic = 'force-dynamic'
```

However, you will commonly use functions like `cookies()`, `headers()`, or reading the incoming `searchParams` from the page props, which will automatically make the page render dynamically. In this case, you do _not_ need to explicitly use `force-dynamic`.

### Fetching data on the client

Expand Down

0 comments on commit 63e0298

Please sign in to comment.