Unverified Commit 22ca7677 authored by Delba de Oliveira's avatar Delba de Oliveira Committed by GitHub
parent 5d4f2de0
......@@ -41,8 +41,20 @@ After the prompts, [`create-next-app`](/docs/app/api-reference/cli/create-next-a
To manually create a new Next.js app, install the required packages:
```bash filename="Terminal"
npm install next@latest react@latest react-dom@latest
```bash package="pnpm"
pnpm i next@latest react@latest react-dom@latest
```
```bash package="npm"
npm i next@latest react@latest react-dom@latest
```
```bash package="yarn"
yarn add next@latest react@latest react-dom@latest
```
```bash package="bun"
bun add next@latest react@latest react-dom@latest
```
Then, add the following scripts to your `package.json` file:
......
......@@ -80,9 +80,7 @@ export default function Page() {
}
```
### Statically imported images
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.
If the image is statically imported, 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). These values are used to determine the image ratio and prevent [Cumulative Layout Shift](https://web.dev/articles/cls) while your image is loading.
```tsx filename="app/page.tsx" switcher
import Image from 'next/image'
......@@ -120,8 +118,6 @@ export default function Page() {
}
```
In this case, Next.js expects the `app/profile.png` file to be available.
## Remote images
To use a remote image, you can provide a URL string for the `src` property.
......@@ -156,7 +152,7 @@ export default function Page() {
}
```
Since Next.js does not have access to remote files during the build process, you'll need to provide the [`width`](/docs/app/api-reference/components/image#width-and-height), [`height`](/docs/app/api-reference/components/image#width-and-height) and optional [`blurDataURL`](/docs/app/api-reference/components/image#blurdataurl) props manually. The `width` and `height` are used to infer the correct aspect ratio of image and avoid layout shift from the image loading in.
Since Next.js does not have access to remote files during the build process, you'll need to provide the [`width`](/docs/app/api-reference/components/image#width-and-height), [`height`](/docs/app/api-reference/components/image#width-and-height) and optional [`blurDataURL`](/docs/app/api-reference/components/image#blurdataurl) props manually. The `width` and `height` are used to infer the correct aspect ratio of image and avoid layout shift from the image loading in. Alternatively, you can use the [`fill` property](/docs/app/api-reference/components/image#fill) to make the image fill the size of the parent element.
To safely allow images from remote servers, you need to define a list of supported URL patterns in [`next.config.js`](/docs/app/api-reference/config/next-config-js). Be as specific as possible to prevent malicious usage. For example, the following configuration will only allow images from a specific AWS S3 bucket:
......
......@@ -133,7 +133,7 @@ export default function RootLayout({ children }) {
## Local fonts
To use a local font, import your font from `next/font/local` and specify the [`src`](/docs/app/api-reference/components/font#src) of your local font file. Fonts can be stored in the [`public`](/docs/app/api-reference/file-conventions/public-folder) folder. For example:
To use a local font, import your font from `next/font/local` and specify the [`src`](/docs/app/api-reference/components/font#src) of your local font file. Fonts can be stored in the [`public`](/docs/app/api-reference/file-conventions/public-folder) folder or co-located inside the `app` folder. For example:
```tsx filename="app/layout.tsx" switcher
import localFont from 'next/font/local'
......
......@@ -186,8 +186,7 @@ export default function RootLayout({ children }) {
<PagesOnly>
Next.js allows you to import CSS files from a JavaScript file.
This is possible because Next.js extends the concept of [`import`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import) beyond JavaScript.
Next.js allows you to import CSS files from a JavaScript file. This is possible because Next.js extends the concept of [`import`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import) beyond JavaScript.
### Import styles from `node_modules`
......
......@@ -177,23 +177,7 @@ To reduce the size of your client JavaScript bundles, add `'use client'` to spec
For example, the `<Layout>` component contains mostly static elements like a logo and navigation links, but includes an interactive search bar. `<Search />` is interactive and needs to be a Client Component, however, the rest of the layout can remain a Server Component.
```tsx filename="app/ui/search.tsx" highlight={1} switcher
'use client'
export default function Search() {
// ...
}
```
```jsx filename="app/ui/search.js" highlight={1} switcher
'use client'
export default function Search() {
// ...
}
```
```tsx filename="app/layout.tsx" switcher
```tsx filename="app/layout.tsx" highlight={12} switcher
// Client Component
import Search from './search'
// Server Component
......@@ -213,7 +197,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {
}
```
```jsx filename="app/layout.js" switcher
```jsx filename="app/layout.js" highlight={12} switcher
// Client Component
import Search from './search'
// Server Component
......@@ -233,6 +217,22 @@ export default function Layout({ children }) {
}
```
```tsx filename="app/ui/search.tsx" highlight={1} switcher
'use client'
export default function Search() {
// ...
}
```
```jsx filename="app/ui/search.js" highlight={1} switcher
'use client'
export default function Search() {
// ...
}
```
### Passing data from Server to Client Components
You can pass data from Server Components to Client Components using props.
......
......@@ -172,7 +172,7 @@ export default function ClientComponent({ updateItemAction }) {
There are two main ways you can invoke a Server Function:
1. [Forms](#forms) in Server and Client Components
2. [Event Handlers](#event-handlers) in Client Components
2. [Event Handlers](#event-handlers) and [useEffect](#useeffect) in Client Components
### Forms
......@@ -428,7 +428,7 @@ export async function exampleAction() {
}
```
### `useEffect`
### useEffect
You can use the React [`useEffect`](https://react.dev/reference/react/useEffect) hook to invoke a Server Action when the component mounts or a dependency changes. This is useful for mutations that depend on global events or need to be triggered automatically. For example, `onKeyDown` for app shortcuts, an intersection observer hook for infinite scrolling, or when the component mounts to update a view count:
......
......@@ -15,15 +15,27 @@ related:
To update to the latest version of Next.js, you can use the `upgrade` codemod:
```bash filename="Terminal"
npx @next/codemod@canary upgrade latest
npx @next/codemod@latest upgrade latest
```
If you prefer to upgrade manually, install the latest Next.js and React versions:
```bash filename="Terminal"
```bash package="pnpm"
pnpm i next@latest react@latest react-dom@latest eslint-config-next@latest
```
```bash package="npm"
npm i next@latest react@latest react-dom@latest eslint-config-next@latest
```
```bash package="yarn"
yarn add next@latest react@latest react-dom@latest eslint-config-next@latest
```
```bash package="bun"
bun add next@latest react@latest react-dom@latest eslint-config-next@latest
```
## Canary version
To update to the latest canary, make sure you're on the latest version of Next.js and everything is working as expected. Then, run the following command:
......
......@@ -102,7 +102,7 @@ The `width` and `height` properties represent the [intrinsic](https://developer.
You **must** set both `width` and `height` properties unless:
- The image is [statically imported](/docs/app/getting-started/images#local-images)
- The image is statically imported.
- The image has the [`fill` property](#fill)
If the height and width are unknown, we recommend using the [`fill` property](#fill).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment