Skip to content

Commit

Permalink
fix: Reusing data across multiple functions example
Browse files Browse the repository at this point in the history
  • Loading branch information
hyungjikim committed Nov 23, 2024
1 parent 6aaa51d commit ad59fa0
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ If you are using `fetch`, requests can be [memoized](/docs/app/building-your-app
>
> - In previous versions of Next.js, using `fetch` would have a default `cache` value of `force-cache`. This changed in version 15, to a default of `cache: no-store`.
```tsx filename="app/page.tsx" switcher
```tsx filename="app/blog/[id]/page.tsx" switcher
import { notFound } from 'next/navigation'

interface Post {
Expand All @@ -295,7 +295,7 @@ export async function generateStaticParams() {
}).then((res) => res.json())

return posts.map((post: Post) => ({
id: post.id,
id: String(post.id),
}))
}

Expand All @@ -304,7 +304,8 @@ export async function generateMetadata({
}: {
params: Promise<{ id: string }>
}) {
let post = await getPost(params.id)
const { id } = await params
let post = await getPost(id)

return {
title: post.title,
Expand All @@ -316,7 +317,8 @@ export default async function Page({
}: {
params: Promise<{ id: string }>
}) {
let post = await getPost(params.id)
const { id } = await params
let post = await getPost(id)

return (
<article>
Expand All @@ -327,7 +329,7 @@ export default async function Page({
}
```

```jsx filename="app/page.js" switcher
```jsx filename="app/blog/[id]/page.js" switcher
import { notFound } from 'next/navigation'

async function getPost(id) {
Expand All @@ -343,20 +345,22 @@ export async function generateStaticParams() {
)

return posts.map((post) => ({
id: post.id,
id: String(post.id),
}))
}

export async function generateMetadata({ params }) {
let post = await getPost(params.id)
const { id } = await params
let post = await getPost(id)

return {
title: post.title,
}
}

export default async function Page({ params }) {
let post = await getPost(params.id)
const { id } = await params
let post = await getPost(id)

return (
<article>
Expand Down

0 comments on commit ad59fa0

Please sign in to comment.