You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/01-app/03-api-reference/03-file-conventions/01-metadata/app-icons.mdx
+20-11Lines changed: 20 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -177,25 +177,33 @@ The default export function receives the following props:
177
177
178
178
#### `params` (optional)
179
179
180
-
An object containing the [dynamic route parameters](/docs/app/api-reference/file-conventions/dynamic-routes) object from the root segment down to the segment `icon` or `apple-icon` is colocated in.
180
+
A promise that resolves to an object containing the [dynamic route parameters](/docs/app/api-reference/file-conventions/dynamic-routes) object from the root segment down to the segment `icon` or `apple-icon` is colocated in.
181
+
182
+
> **Good to know**: If you use [`generateImageMetadata`](/docs/app/api-reference/functions/generate-image-metadata), the function will also receive an `id` prop that is a promise resolving to the `id` value from one of the items returned by `generateImageMetadata`.
Copy file name to clipboardExpand all lines: docs/01-app/03-api-reference/03-file-conventions/01-metadata/opengraph-image.mdx
+29-14Lines changed: 29 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -220,25 +220,33 @@ The default export function receives the following props:
220
220
221
221
#### `params` (optional)
222
222
223
-
An object containing the [dynamic route parameters](/docs/app/api-reference/file-conventions/dynamic-routes) object from the root segment down to the segment `opengraph-image` or `twitter-image` is colocated in.
223
+
A promise that resolves to an object containing the [dynamic route parameters](/docs/app/api-reference/file-conventions/dynamic-routes) object from the root segment down to the segment `opengraph-image` or `twitter-image` is colocated in.
224
+
225
+
> **Good to know**: If you use [`generateImageMetadata`](/docs/app/api-reference/functions/generate-image-metadata), the function will also receive an `id` prop that is a promise resolving to the `id` value from one of the items returned by `generateImageMetadata`.
Copy file name to clipboardExpand all lines: docs/01-app/03-api-reference/04-functions/generate-image-metadata.mdx
+60-12Lines changed: 60 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ export function generateImageMetadata({ params }) {
42
42
43
43
## Returns
44
44
45
-
The `generateImageMetadata` function should return an `array` of objects containing the image's metadata such as `alt` and `size`. In addition, each item **must** include an `id` value which will be passed to the props of the image generating function.
45
+
The `generateImageMetadata` function should return an `array` of objects containing the image's metadata such as `alt` and `size`. In addition, each item **must** include an `id` value which will be passed as a promise to the props of the image generating function.
@@ -69,7 +69,8 @@ export function generateImageMetadata() {
69
69
]
70
70
}
71
71
72
-
exportdefaultfunction Icon({ id }: { id:string }) {
72
+
exportdefaultasyncfunction Icon({ id }: { id:Promise<string|number> }) {
73
+
const iconId =awaitid
73
74
returnnewImageResponse(
74
75
(
75
76
<div
@@ -84,7 +85,7 @@ export default function Icon({ id }: { id: string }) {
84
85
color: '#fafafa',
85
86
}}
86
87
>
87
-
Icon {id}
88
+
Icon {iconId}
88
89
</div>
89
90
)
90
91
)
@@ -109,7 +110,8 @@ export function generateImageMetadata() {
109
110
]
110
111
}
111
112
112
-
exportdefaultfunctionIcon({ id }) {
113
+
exportdefaultasyncfunctionIcon({ id }) {
114
+
consticonId=await id
113
115
returnnewImageResponse(
114
116
(
115
117
<div
@@ -124,13 +126,57 @@ export default function Icon({ id }) {
124
126
color:'#fafafa',
125
127
}}
126
128
>
127
-
Icon {id}
129
+
Icon {iconId}
128
130
</div>
129
131
)
130
132
)
131
133
}
132
134
```
133
135
136
+
## Image generation function props
137
+
138
+
When using `generateImageMetadata`, the default export image generation function receives the following props:
139
+
140
+
#### `id`
141
+
142
+
A promise that resolves to the `id` value from one of the items returned by `generateImageMetadata`. The `id` will be a `string` or `number` depending on what was returned from `generateImageMetadata`.
143
+
144
+
```tsx filename="icon.tsx" switcher
145
+
exportdefaultasyncfunction Icon({ id }: { id:Promise<string|number> }) {
146
+
const iconId =awaitid
147
+
// Use iconId to generate the image
148
+
}
149
+
```
150
+
151
+
```jsx filename="icon.js" switcher
152
+
exportdefaultasyncfunctionIcon({ id }) {
153
+
consticonId=await id
154
+
// Use iconId to generate the image
155
+
}
156
+
```
157
+
158
+
#### `params` (optional)
159
+
160
+
A promise that resolves to an object containing the [dynamic route parameters](/docs/app/api-reference/file-conventions/dynamic-routes) from the root segment down to the segment the image is colocated in.
161
+
162
+
```tsx filename="icon.tsx" switcher
163
+
exportdefaultasyncfunction Icon({
164
+
params,
165
+
}: {
166
+
params:Promise<{ slug:string }>
167
+
}) {
168
+
const { slug } =awaitparams
169
+
// Use slug to generate the image
170
+
}
171
+
```
172
+
173
+
```jsx filename="icon.js" switcher
174
+
exportdefaultasyncfunctionIcon({ params }) {
175
+
const { slug } =await params
176
+
// Use slug to generate the image
177
+
}
178
+
```
179
+
134
180
### Examples
135
181
136
182
#### Using external data
@@ -160,11 +206,11 @@ export default async function Image({
160
206
params,
161
207
id,
162
208
}: {
163
-
params: { id:string }
164
-
id:number
209
+
params:Promise<{ id:string }>
210
+
id:Promise<number>
165
211
}) {
166
212
const productId = (awaitparams).id
167
-
const imageId =id
213
+
const imageId =awaitid
168
214
const text =awaitgetCaptionForImage(productId, imageId)
0 commit comments