Unverified Commit 9df4e061 authored by Gustavo Steinmetz's avatar Gustavo Steinmetz Committed by GitHub

Update Local Images Example to Use Assets Folder (#47878)

This pull request updates the Local Images example in the Next.js
documentation to use an ``assets`` folder inside the ``src`` directory
instead of the ``public`` folder. The changes are made to emphasize the
recommended practice of organizing and importing static assets when
using the Next.js ``Image`` component.

The previous example could cause confusion as it suggested importing
images from the ``public`` folder, which is generally used for static
files that can be accessed directly via a URL. However, when using the
Next.js ``Image`` component, it is recommended to import images as
modules and store them in a folder like ``assets`` inside the ``src``
directory. This approach allows the Image component to optimize images
and prevent Cumulative Layout Shift while loading.

This PR changes the image import statements as the example below:

```jsx
import profilePic from '@/assets/me.png';
```

These changes aim to provide clearer guidance on how to handle local
images. To avoid misunderstandings while the developer follows the
documentation.

---------
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 0f19c983
......@@ -35,7 +35,7 @@ Now, you can define the `src` for your image (either local or remote).
To use a local image, `import` your `.jpg`, `.png`, or `.webp` files:
```jsx
import profilePic from '../public/me.png'
import profilePic from '../assets/me.png'
```
Dynamic `await import()` or `require()` are _not_ supported. The `import` must be static so it can be analyzed at build time.
......@@ -44,7 +44,7 @@ Next.js will automatically determine the `width` and `height` of your image base
```js
import Image from 'next/image'
import profilePic from '../public/me.png'
import profilePic from '../assets/me.png'
function Home() {
return (
......
......@@ -185,7 +185,7 @@ Instead, use the built-in [`next/image`](/docs/api-reference/next/image.md) comp
```jsx
import Image from 'next/image'
import profilePic from '../public/me.png'
import profilePic from '../assets/me.png'
export default function Home() {
return (
......
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