diff --git a/src/content/reference/react-dom/components/img.md b/src/content/reference/react-dom/components/img.md index 4a1f45077..fc712cb7f 100644 --- a/src/content/reference/react-dom/components/img.md +++ b/src/content/reference/react-dom/components/img.md @@ -4,7 +4,7 @@ title: "" -The [built-in browser `` component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img) lets you embed an image. +[ブラウザ組み込みの `` コンポーネント](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img)を使うことで、画像を埋め込むことができます。 ```js A person walking through a park @@ -16,50 +16,50 @@ The [built-in browser `` component](https://developer.mozilla.org/en-US/doc --- -## Reference {/*reference*/} +## リファレンス {/*reference*/} ### `` {/*img*/} -To display an image, render the [built-in browser `` component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img). +画像を表示するには、[ブラウザ組み込みの `` コンポーネント](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img)をレンダーします。 ```js A person walking through a park ``` -[See more examples below.](#usage) +[さらに例を見る](#usage) -#### Props {/*props*/} +#### props {/*props*/} -`` supports all [common element props.](/reference/react-dom/components/common#common-props) +`` は、[一般的な要素の props](/reference/react-dom/components/common#common-props) をすべてサポートしています。 -* `alt`: a string. Specifies alternative text for the image. Use an empty string for a purely decorative image. -* `crossOrigin`: a string. Specifies the [CORS policy](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) to use when fetching the image. The possible values are `anonymous` and `use-credentials`. -* `decoding`: a string. Suggests whether the browser should wait to decode the image before presenting other content. The possible values are `async`, `sync`, and `auto` (the default). -* `fetchPriority`: a string. Suggests a relative priority for fetching the image. The possible values are `high`, `low`, and `auto` (the default). During server rendering, `fetchPriority="low"` also prevents React from [automatically preloading the image.](#controlling-image-preloading-during-server-rendering) -* `height`: a number or string. Specifies the rendered height of the image. -* `loading`: a string. Specifies whether the browser should defer loading the image until it is near the viewport. The possible values are `eager` (the default) and `lazy`. Setting `loading="lazy"` prevents React from [automatically preloading the image.](#controlling-image-preloading-during-server-rendering) -* `onError`: an [event handler](/reference/react-dom/components/common#event-handler) function. Fires when the image fails to load. -* `onLoad`: an [event handler](/reference/react-dom/components/common#event-handler) function. Fires when the image finishes loading. Passing `onLoad` prevents React from [waiting for the image during a client-rendered View Transition update.](#waiting-for-an-image-during-a-view-transition) -* `referrerPolicy`: a string. Specifies the [referrer information](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#referrerpolicy) to send when fetching the image. -* `sizes`: a string. Specifies the image sizes for different page layouts. Used with `srcSet`. -* `src`: a string. Specifies the URL of the image. -* `srcSet`: a string. Specifies one or more candidate image sources for the browser to choose from. -* `useMap`: a string. Associates the image with a [client-side image map](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/map). -* `width`: a number or string. Specifies the rendered width of the image. +* `alt`: 文字列。画像の代替テキストを指定します。純粋に装飾目的の画像には空文字列を使用します。 +* `crossOrigin`: 文字列。画像のフェッチ時に使用する [CORS ポリシー](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin)を指定します。可能な値は `anonymous` と `use-credentials` です。 +* `decoding`: 文字列。他のコンテンツを表示する前に、ブラウザが画像のデコードを待つべきかどうかのヒントです。可能な値は `async`、`sync`、`auto`(デフォルト)です。 +* `fetchPriority`: 文字列。画像のフェッチに対する相対的な優先度のヒントです。可能な値は `high`、`low`、`auto`(デフォルト)です。サーバレンダリング中は、`fetchPriority="low"` を指定すると、React による[画像の自動プリロード](#controlling-image-preloading-during-server-rendering)も行われなくなります。 +* `height`: 数値または文字列。画像の表示時の高さを指定します。 +* `loading`: 文字列。画像がビューポートの近くに来るまで、ブラウザが画像の読み込みを遅延させるかどうかを指定します。可能な値は `eager`(デフォルト)と `lazy` です。`loading="lazy"` を設定すると、React による[画像の自動プリロード](#controlling-image-preloading-during-server-rendering)が行われなくなります。 +* `onError`: [イベントハンドラ](/reference/react-dom/components/common#event-handler)関数。画像の読み込みに失敗したときに発火します。 +* `onLoad`: [イベントハンドラ](/reference/react-dom/components/common#event-handler)関数。画像の読み込みが完了したときに発火します。`onLoad` を渡すと、[クライアントでのレンダーによるビュー遷移 (View Transition) の更新中に、React が画像を待機する動作](#waiting-for-an-image-during-a-view-transition)が行われなくなります。 +* `referrerPolicy`: 文字列。画像のフェッチ時に送信する[リファラ情報](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#referrerpolicy)を指定します。 +* `sizes`: 文字列。ページレイアウトごとの画像サイズを指定します。`srcSet` と組み合わせて使用します。 +* `src`: 文字列。画像の URL を指定します。 +* `srcSet`: 文字列。ブラウザが選択できる画像ソースの候補を 1 つ以上指定します。 +* `useMap`: 文字列。画像を[クライアントサイドイメージマップ](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/map)と関連付けます。 +* `width`: 数値または文字列。画像の表示時の幅を指定します。 -#### Caveats {/*caveats*/} +#### 注意点 {/*caveats*/} -* Do not pass an empty string to `src`. It may cause the browser to request the current page again. React warns in development and omits the attribute. To render no image, omit the `` or pass `null` to `src`. -* `` cannot have children or use `dangerouslySetInnerHTML`. React throws an error if you pass either. -* `fetchPriority="low"` does not stop React from waiting for the image to load and decode during a client-rendered View Transition update. Use `loading="lazy"` or an `onLoad` handler to opt out of that behavior. +* `src` に空文字列を渡さないでください。ブラウザが現在のページを再度リクエストしてしまう可能性があります。React は開発環境では警告を表示し、この属性を省略します。画像を何も表示しない場合は、`` 自体を省略するか、`src` に `null` を渡してください。 +* `` は子要素を持つことができず、`dangerouslySetInnerHTML` も使用できません。いずれかを渡すと React はエラーをスローします。 +* `fetchPriority="low"` を指定しても、クライアントでのレンダーによるビュー遷移の更新中に React が画像の読み込みを待機する動作は止まりません。この動作をオプトアウトするには、`loading="lazy"` を指定するか `onLoad` ハンドラを渡してください。 --- -## Usage {/*usage*/} +## 使用法 {/*usage*/} -### Displaying an image {/*displaying-an-image*/} +### 画像を表示する {/*displaying-an-image*/} -Pass the image URL to `src` and a text description to `alt`: +`src` に画像の URL を、`alt` にテキストによる説明を渡します。 @@ -85,15 +85,15 @@ img { -Specify `width` and `height` when you know the image dimensions so the browser can reserve space before the image loads. For a decorative image, pass `alt=""` so that screen readers ignore it. +画像のサイズが分かっている場合は `width` と `height` を指定してください。これにより、ブラウザが画像の読み込み前に表示領域を確保できるようになります。装飾目的の画像には `alt=""` を渡して、スクリーンリーダに無視されるようにしてください。 --- -### Controlling image preloading during server rendering {/*controlling-image-preloading-during-server-rendering*/} +### サーバレンダリング中の画像のプリロードを制御する {/*controlling-image-preloading-during-server-rendering*/} -During server rendering, React automatically generates a preload hint for an `` by default. This can let the browser start fetching the image before it encounters the `` in the rendered HTML. +サーバレンダリング中、React はデフォルトで `` に対するプリロードヒントを自動的に生成します。これにより、ブラウザはレンダーされた HTML 内で `` に出会う前に、画像のフェッチを開始できるようになります。 -Add `loading="lazy"` or `fetchPriority="low"` to an image that should not receive this hint: +このヒントを生成すべきでない画像には、`loading="lazy"` または `fetchPriority="low"` を追加します。 ```js function ProductPage() { @@ -107,43 +107,44 @@ function ProductPage() { } ``` -In this example, React generates a preload hint only for `hero.jpg`. Depending on the server API or framework, React may render the equivalent of this element: +この例では、React は `hero.jpg` に対してのみプリロードヒントを生成します。使用するサーバ API やフレームワークによっては、React は以下のような要素に相当するものをレンダーすることがあります。 ```html ``` -React may instead provide the same hint in a `Link` response header. The other two images keep their `loading` and `fetchPriority` props in the rendered HTML, but React does not generate preload hints for them. The `loading="lazy"` prop asks the browser to defer loading an image until it approaches the viewport. The `fetchPriority="low"` prop allows the image to load immediately, but tells the browser to fetch it at a lower priority. +代わりに、同じヒントを `Link` レスポンスヘッダで提供する場合もあります。残りの 2 つの画像については、レンダーされた HTML に `loading` や `fetchPriority` の props がそのまま残りますが、React はプリロードヒントを生成しません。`loading="lazy"` は、画像がビューポートに近づくまで読み込みを遅延させるようブラウザに求めます。`fetchPriority="low"` は画像をすぐに読み込むことを許可しますが、低い優先度でフェッチするようブラウザに伝えます。 -React also does not automatically preload an image when it is inside a `` or `