Skip to content

Commit

Permalink
Add section about migrating from next/image to next/future/image (#…
Browse files Browse the repository at this point in the history
…39270)

This expands on the previous PR #38978 with a section on migrating
  • Loading branch information
styfle committed Aug 2, 2022
1 parent b799710 commit 213c42f
Showing 1 changed file with 127 additions and 4 deletions.
131 changes: 127 additions & 4 deletions docs/api-reference/next/future/image.md
Expand Up @@ -30,6 +30,8 @@ module.exports = {
}
```

## Comparison

Compared to `next/image`, the new `next/future/image` component has the following changes:

- Renders a single `<img>` without `<div>` or `<span>` wrappers
Expand All @@ -39,13 +41,134 @@ Compared to `next/image`, the new `next/future/image` component has the followin
- Removes `loader` config in favor of [`loader`](#loader) prop
- Note: the [`onError`](#onerror) prop might behave differently

The default layout for `next/image` was `intrinsic`, which would shrink the `width` if the image was larger than it's container. Since no styles are automatically applied to `next/future/image`, you'll need to add the following CSS to achieve the same behavior:
## Migration

Although `layout` is not available, you can migrate `next/image` to `next/future/image` using a few props. The following is a comparison of the two components:

<table>
<thead>
<tr>
<th>next/image</th>
<th>next/future/image</th>
</tr>
</thead>
<tbody>

<tr>
<td>

```jsx
import Image from 'next/image'
import img from '../img.png'

function Page() {
return <Image src={img} />
}
```

</td>
<td>

```jsx
import Image from 'next/future/image'
import img from '../img.png'

const css = { maxWidth: '100%', height: 'auto' }
function Page() {
return <Image src={img} style={css} />
}
```

</td>
</tr>

<tr>
<td>

```jsx
import Image from 'next/image'
import img from '../img.png'

```css
max-width: 100%;
height: auto;
function Page() {
return <Image src={img} layout="responsive" />
}
```

</td>
<td>

```jsx
import Image from 'next/future/image'
import img from '../img.png'

const css = { width: '100%', height: 'auto' }
function Page() {
return <Image src={img} sizes="100vw" style={css} />
}
```

</td>
</tr>

<tr>
<td>

```jsx
import Image from 'next/image'
import img from '../img.png'

function Page() {
return <Image src={img} layout="fill" />
}
```

</td>
<td>

```jsx
import Image from 'next/future/image'
import img from '../img.png'

function Page() {
return <Image src={img} sizes="100vw" fill />
}
```

</td>
</tr>

<tr>
<td>

```jsx
import Image from 'next/image'
import img from '../img.png'

function Page() {
return <Image src={img} layout="fixed" />
}
```

</td>
<td>

```jsx
import Image from 'next/future/image'
import img from '../img.png'

function Page() {
return <Image src={img} />
}
```

</td>
</tr>

</tbody>
</table>

You can also use `className` instead of `style`.

## Required Props

The `<Image />` component requires the following properties.
Expand Down

0 comments on commit 213c42f

Please sign in to comment.