Unverified Commit 7aa8c2c7 authored by Steven's avatar Steven Committed by GitHub

Update docs to use <Image> instead of <img> (#19160)

This unifies the docs to always use `<Image>` instead of `<img>` so we can set readers up for success.
parent f4c2c6d4
...@@ -32,6 +32,7 @@ To get access to the runtime configs in your app use `next/config`, like so: ...@@ -32,6 +32,7 @@ To get access to the runtime configs in your app use `next/config`, like so:
```jsx ```jsx
import getConfig from 'next/config' import getConfig from 'next/config'
import Image from 'next/image'
// Only holds serverRuntimeConfig and publicRuntimeConfig // Only holds serverRuntimeConfig and publicRuntimeConfig
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig() const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
...@@ -43,7 +44,11 @@ console.log(publicRuntimeConfig.staticFolder) ...@@ -43,7 +44,11 @@ console.log(publicRuntimeConfig.staticFolder)
function MyImage() { function MyImage() {
return ( return (
<div> <div>
<img src={`${publicRuntimeConfig.staticFolder}/logo.png`} alt="logo" /> <Image
src={`${publicRuntimeConfig.staticFolder}/logo.png`}
alt="logo"
layout="fill"
/>
</div> </div>
) )
} }
......
...@@ -202,12 +202,21 @@ The default behavior of the `Link` component is to `push` a new URL into the `hi ...@@ -202,12 +202,21 @@ The default behavior of the `Link` component is to `push` a new URL into the `hi
`Link` supports any component that supports the `onClick` event, in the case you don't provide an `<a>` tag, consider the following example: `Link` supports any component that supports the `onClick` event, in the case you don't provide an `<a>` tag, consider the following example:
```jsx ```jsx
<Link href="/about"> import Link from 'next/link'
<img src="/static/image.png" alt="image" /> import Image from 'next/image'
</Link>
function Avatar() {
return (
<Link href="/about">
<Image src="/me.png" alt="me" width="64" height="64" />
</Link>
)
}
export default Avatar
``` ```
The child of `Link` is `<img>` instead of `<a>`. `Link` will send the `onClick` property to `<img>` but won't pass the `href` property. The child of `Link` is [`Image`](/docs/api-reference/next/image.md) instead of `<a>`. `Link` will send the `onClick` property to `Image` but won't pass the `href` property.
## Disable scrolling to the top of the page ## Disable scrolling to the top of the page
......
...@@ -6,14 +6,16 @@ description: Next.js allows you to serve static files, like images, in the publi ...@@ -6,14 +6,16 @@ description: Next.js allows you to serve static files, like images, in the publi
Next.js can serve static files, like images, under a folder called `public` in the root directory. Files inside `public` can then be referenced by your code starting from the base URL (`/`). Next.js can serve static files, like images, under a folder called `public` in the root directory. Files inside `public` can then be referenced by your code starting from the base URL (`/`).
For example, if you add an image to `public/my-image.png`, the following code will access the image: For example, if you add an image to `public/me.png`, the following code will access the image:
```jsx ```jsx
function MyImage() { import Image from 'next/image'
return <img src="/my-image.png" alt="my image" />
function Avatar() {
return <Image src="/me.png" alt="me" width="64" height="64" />
} }
export default MyImage export default Avatar
``` ```
This folder is also useful for `robots.txt`, `favicon.ico`, Google Site Verification, and any other static files (including `.html`)! This folder is also useful for `robots.txt`, `favicon.ico`, Google Site Verification, and any other static files (including `.html`)!
......
...@@ -25,14 +25,14 @@ ...@@ -25,14 +25,14 @@
"title": "Image Optimization", "title": "Image Optimization",
"path": "/docs/basic-features/image-optimization.md" "path": "/docs/basic-features/image-optimization.md"
}, },
{
"title": "Fast Refresh",
"path": "/docs/basic-features/fast-refresh.md"
},
{ {
"title": "Static File Serving", "title": "Static File Serving",
"path": "/docs/basic-features/static-file-serving.md" "path": "/docs/basic-features/static-file-serving.md"
}, },
{
"title": "Fast Refresh",
"path": "/docs/basic-features/fast-refresh.md"
},
{ {
"title": "TypeScript", "title": "TypeScript",
"path": "/docs/basic-features/typescript.md" "path": "/docs/basic-features/typescript.md"
......
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