Skip to content

Commit 44bb6a0

Browse files
committed
docs: update nextjs documentation
1 parent 9682b69 commit 44bb6a0

File tree

4 files changed

+115
-62
lines changed

4 files changed

+115
-62
lines changed

apps/docs/content/en/docs/01-app/01-getting-started/04-images.mdx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,41 @@ export default function Page() {
5858
<Image
5959
src="/profile.png"
6060
alt="Picture of the author"
61+
width={500}
62+
height={500}
63+
/>
64+
)
65+
}
66+
```
67+
68+
```jsx filename="app/page.js" switcher
69+
import Image from 'next/image'
70+
71+
export default function Page() {
72+
return (
73+
<Image
74+
src="/profile.png"
75+
alt="Picture of the author"
76+
width={500}
77+
height={500}
78+
/>
79+
)
80+
}
81+
```
82+
83+
### Statically imported images
84+
85+
You can also import and use local image files. Next.js will automatically determine the intrinsic [`width`](/docs/app/api-reference/components/image#width-and-height) and [`height`](/docs/app/api-reference/components/image#width-and-height) of your image based on the imported file. These values are used to determine the image ratio and prevent [Cumulative Layout Shift](https://web.dev/articles/cls) while your image is loading.
86+
87+
```tsx filename="app/page.tsx" switcher
88+
import Image from 'next/image'
89+
import ProfileImage from './profile.png'
90+
91+
export default function Page() {
92+
return (
93+
<Image
94+
src={ProfileImage}
95+
alt="Picture of the author"
6196
// width={500} automatically provided
6297
// height={500} automatically provided
6398
// blurDataURL="data:..." automatically provided
@@ -69,11 +104,12 @@ export default function Page() {
69104

70105
```jsx filename="app/page.js" switcher
71106
import Image from 'next/image'
107+
import ProfileImage from './profile.png'
72108

73109
export default function Page() {
74110
return (
75111
<Image
76-
src="/profile.png"
112+
src={ProfileImage}
77113
alt="Picture of the author"
78114
// width={500} automatically provided
79115
// height={500} automatically provided
@@ -84,7 +120,7 @@ export default function Page() {
84120
}
85121
```
86122

87-
When using local images, Next.js will automatically determine the intrinsic [`width`](/docs/app/api-reference/components/image#width-and-height) and [`height`](/docs/app/api-reference/components/image#width-and-height) of your image based on the imported file. These values are used to determine the image ratio and prevent [Cumulative Layout Shift](https://web.dev/articles/cls) while your image is loading.
123+
In this case, Next.js expects the `app/profile.png` file to be available.
88124

89125
## Remote images
90126

apps/docs/content/en/docs/01-app/05-api-reference/03-file-conventions/route-segment-config.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export const dynamicParams = true // true | false,
8787
> - This option replaces the `fallback: true | false | blocking` option of `getStaticPaths` in the `pages` directory.
8888
> - To statically render all paths the first time they're visited, you'll need to return an empty array in `generateStaticParams` or utilize `export const dynamic = 'force-static'`.
8989
> - When `dynamicParams = true`, the segment uses [Streaming Server Rendering](/docs/app/building-your-application/routing/loading-ui-and-streaming#streaming-with-suspense).
90-
> - If the `dynamic = 'error'` and `dynamic = 'force-static'` are used, it'll change the default of `dynamicParams` to `false`.
9190
9291
### `revalidate`
9392

apps/docs/content/en/docs/01-app/05-api-reference/04-functions/use-report-web-vitals.mdx

Lines changed: 74 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ description: API Reference for the useReportWebVitals function.
77

88
The `useReportWebVitals` hook allows you to report [Core Web Vitals](https://web.dev/vitals/), and can be used in combination with your analytics service.
99

10+
New functions passed to `useReportWebVitals` are called with the available metrics up to that point. To prevent reporting duplicated data, ensure that the callback function reference does not change (as shown in the code examples below).
11+
1012
<PagesOnly>
1113

1214
```jsx filename="pages/_app.js"
1315
import { useReportWebVitals } from 'next/web-vitals'
1416

17+
const logWebVitals = (metric) => {
18+
console.log(metric)
19+
}
20+
1521
function MyApp({ Component, pageProps }) {
16-
useReportWebVitals((metric) => {
17-
console.log(metric)
18-
})
22+
useReportWebVitals(logWebVitals)
1923

2024
return <Component {...pageProps} />
2125
}
@@ -30,10 +34,12 @@ function MyApp({ Component, pageProps }) {
3034

3135
import { useReportWebVitals } from 'next/web-vitals'
3236

37+
const logWebVitals = (metric) => {
38+
console.log(metric)
39+
}
40+
3341
export function WebVitals() {
34-
useReportWebVitals((metric) => {
35-
console.log(metric)
36-
})
42+
useReportWebVitals(logWebVitals)
3743

3844
return null
3945
}
@@ -89,18 +95,20 @@ You can handle all the results of these metrics using the `name` property.
8995
```jsx filename="pages/_app.js"
9096
import { useReportWebVitals } from 'next/web-vitals'
9197

92-
function MyApp({ Component, pageProps }) {
93-
useReportWebVitals((metric) => {
94-
switch (metric.name) {
95-
case 'FCP': {
96-
// handle FCP results
97-
}
98-
case 'LCP': {
99-
// handle LCP results
100-
}
101-
// ...
98+
const handleWebVitals = (metric) => {
99+
switch (metric.name) {
100+
case 'FCP': {
101+
// handle FCP results
102102
}
103-
})
103+
case 'LCP': {
104+
// handle LCP results
105+
}
106+
// ...
107+
}
108+
}
109+
110+
function MyApp({ Component, pageProps }) {
111+
useReportWebVitals(handleWebVitals)
104112

105113
return <Component {...pageProps} />
106114
}
@@ -115,18 +123,22 @@ function MyApp({ Component, pageProps }) {
115123

116124
import { useReportWebVitals } from 'next/web-vitals'
117125

118-
export function WebVitals() {
119-
useReportWebVitals((metric) => {
120-
switch (metric.name) {
121-
case 'FCP': {
122-
// handle FCP results
123-
}
124-
case 'LCP': {
125-
// handle LCP results
126-
}
127-
// ...
126+
type ReportWebVitalsCallback = Parameters<typeof useReportWebVitals>[0]
127+
128+
const handleWebVitals: ReportWebVitalsCallback = (metric) => {
129+
switch (metric.name) {
130+
case 'FCP': {
131+
// handle FCP results
132+
}
133+
case 'LCP': {
134+
// handle LCP results
128135
}
129-
})
136+
// ...
137+
}
138+
}
139+
140+
export function WebVitals() {
141+
useReportWebVitals(handleWebVitals)
130142
}
131143
```
132144

@@ -135,18 +147,20 @@ export function WebVitals() {
135147

136148
import { useReportWebVitals } from 'next/web-vitals'
137149

138-
export function WebVitals() {
139-
useReportWebVitals((metric) => {
140-
switch (metric.name) {
141-
case 'FCP': {
142-
// handle FCP results
143-
}
144-
case 'LCP': {
145-
// handle LCP results
146-
}
147-
// ...
150+
const handleWebVitals = (metric) => {
151+
switch (metric.name) {
152+
case 'FCP': {
153+
// handle FCP results
148154
}
149-
})
155+
case 'LCP': {
156+
// handle LCP results
157+
}
158+
// ...
159+
}
160+
}
161+
162+
export function WebVitals() {
163+
useReportWebVitals(handleWebVitals)
150164
}
151165
```
152166

@@ -169,22 +183,24 @@ You can handle all the results of these metrics separately:
169183
```jsx filename="pages/_app.js"
170184
import { useReportWebVitals } from 'next/web-vitals'
171185

186+
function handleCustomMetrics(metrics) {
187+
switch (metric.name) {
188+
case 'Next.js-hydration':
189+
// handle hydration results
190+
break
191+
case 'Next.js-route-change-to-render':
192+
// handle route-change to render results
193+
break
194+
case 'Next.js-render':
195+
// handle render results
196+
break
197+
default:
198+
break
199+
}
200+
}
201+
172202
function MyApp({ Component, pageProps }) {
173-
useReportWebVitals((metric) => {
174-
switch (metric.name) {
175-
case 'Next.js-hydration':
176-
// handle hydration results
177-
break
178-
case 'Next.js-route-change-to-render':
179-
// handle route-change to render results
180-
break
181-
case 'Next.js-render':
182-
// handle render results
183-
break
184-
default:
185-
break
186-
}
187-
})
203+
useReportWebVitals(handleCustomMetrics)
188204

189205
return <Component {...pageProps} />
190206
}
@@ -200,7 +216,7 @@ You can send results to any endpoint to measure and track
200216
real user performance on your site. For example:
201217

202218
```js
203-
useReportWebVitals((metric) => {
219+
function postWebVitals(metrics) {
204220
const body = JSON.stringify(metric)
205221
const url = 'https://example.com/analytics'
206222

@@ -210,7 +226,9 @@ useReportWebVitals((metric) => {
210226
} else {
211227
fetch(url, { body, method: 'POST', keepalive: true })
212228
}
213-
})
229+
}
230+
231+
useReportWebVitals(postWebVitals)
214232
```
215233

216234
> **Good to know**: If you use [Google Analytics](https://analytics.google.com/analytics/web/), using the

apps/docs/content/en/learn/02-dashboard-app/12-mutating-data.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export async function createInvoice(formData: FormData) {
298298

299299
Now that you have all the values you need for your database, you can create an SQL query to insert the new invoice into your database and pass in the variables:
300300

301-
```ts {2,15,16,17,18} filename="/app/lib/actions.ts"
301+
```ts {2,4,17,18,19,20} filename="/app/lib/actions.ts"
302302
import { z } from 'zod';
303303
import postgres from 'postgres';
304304

@@ -363,7 +363,7 @@ Once the database has been updated, the `/dashboard/invoices` path will be reval
363363

364364
At this point, you also want to redirect the user back to the `/dashboard/invoices` page. You can do this with the [`redirect`](/docs/app/api-reference/functions/redirect) function from Next.js:
365365

366-
```ts {6,14} filename="/app/lib/actions.ts"
366+
```ts {5,16} filename="/app/lib/actions.ts"
367367
'use server';
368368

369369
import { z } from 'zod';
@@ -488,7 +488,7 @@ Notice how it's similar to your `/create` invoice page, except it imports a diff
488488

489489
In addition to `searchParams`, page components also accept a prop called `params` which you can use to access the `id`. Update your `<Page>` component to receive the prop:
490490

491-
```tsx {5,6} filename="/app/dashboard/invoices/[id]/edit/page.tsx"
491+
```tsx {5,6,7} filename="/app/dashboard/invoices/[id]/edit/page.tsx"
492492
import Form from '@/app/ui/invoices/edit-form';
493493
import Breadcrumbs from '@/app/ui/invoices/breadcrumbs';
494494
import { fetchCustomers } from '@/app/lib/data';

0 commit comments

Comments
 (0)