Skip to content

Commit

Permalink
(Docs) add missing js version for generateMetadata. (#52763)
Browse files Browse the repository at this point in the history
There was no JS version for `generateMetadata` function.

fixes #52759 

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
  • Loading branch information
vinaykulk621 and styfle committed Jul 17, 2023
1 parent f5f79e7 commit 503677c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/02-app/02-api-reference/04-functions/generate-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ export async function generateMetadata(
export default function Page({ params, searchParams }: Props) {}
```

```
jsx filename="app/products/[id]/page.js" switcher
export async function generateMetadata({ params, searchParams }, parent) {
// read route params
const id = params.id
// fetch data
const product = await fetch(`https://.../${id}`).then((res) => res.json())
// optionally access and extend (rather than replace) parent metadata
const previousImages = (await parent).openGraph?.images || []
return {
title: product.title,
openGraph: {
images: ['/some-specific-page-image.jpg', ...previousImages],
},
}
}
export default function Page({ params, searchParams }) {}
```

### Parameters

`generateMetadata` function accepts the following parameters:
Expand Down

0 comments on commit 503677c

Please sign in to comment.