Skip to content

Commit 94093ad

Browse files
authored
Translate useId reference (#608)
* Translate up to line 170 * Translate up to line 176 * Translate up to line 180 * Translate up to line 182 * Translate up to line 184 * Translate up to line 219 * Complete * Update styling and correct sentences for readability
1 parent d342344 commit 94093ad

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/content/reference/react/useId.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: useId
44

55
<Intro>
66

7-
`useId` is a React Hook for generating unique IDs that can be passed to accessibility attributes.
7+
`useId` は、アクセシビリティ属性に渡すことができる一意の ID を生成するための React フックです。
88

99
```js
1010
const id = useId()
@@ -16,11 +16,11 @@ const id = useId()
1616

1717
---
1818

19-
## Reference {/*reference*/}
19+
## リファレンス {/*reference*/}
2020

2121
### `useId()` {/*useid*/}
2222

23-
Call `useId` at the top level of your component to generate a unique ID:
23+
コンポーネントのトップレベルで `useId` を呼び出して、一意の ID を生成します。
2424

2525
```js
2626
import { useId } from 'react';
@@ -30,35 +30,35 @@ function PasswordField() {
3030
// ...
3131
```
3232
33-
[See more examples below.](#usage)
33+
[さらに例を見る](#usage)
3434
35-
#### Parameters {/*parameters*/}
35+
#### 引数 {/*parameters*/}
3636
37-
`useId` does not take any parameters.
37+
`useId` はパラメータを受け取りません。
3838
39-
#### Returns {/*returns*/}
39+
#### 返り値 {/*returns*/}
4040
41-
`useId` returns a unique ID string associated with this particular `useId` call in this particular component.
41+
`useId` は、特定のコンポーネント内でこの特定の `useId` の呼び出しに関連付けられた、一意の ID 文字列を返します。
4242
43-
#### Caveats {/*caveats*/}
43+
#### 注意事項 {/*caveats*/}
4444
45-
* `useId` is a Hook, so you can only call it **at the top level of your component** or your own Hooks. You can't call it inside loops or conditions. If you need that, extract a new component and move the state into it.
45+
* `useId` はフックであるため、**コンポーネントのトップレベル**または独自のフック内でのみ呼び出すことができます。ループまたは条件分岐内で呼び出すことはできません。もし必要な場合は、新しいコンポーネントを作成し、状態を移動させる必要があります。
4646
47-
* `useId` **should not be used to generate keys** in a list. [Keys should be generated from your data.](/learn/rendering-lists#where-to-get-your-key)
47+
* `useId` を、**リスト内の key の生成には使用しないでください**。[key はデータから生成される必要があります。](/learn/rendering-lists#where-to-get-your-key)
4848
4949
---
5050
51-
## Usage {/*usage*/}
51+
## 使用方 {/*usage*/}
5252
5353
<Pitfall>
5454
55-
**Do not call `useId` to generate keys in a list.** [Keys should be generated from your data.](/learn/rendering-lists#where-to-get-your-key)
55+
**リスト内の key を生成するために `useId` を呼び出さないでください。**[key はデータから生成される必要があります。](/learn/rendering-lists#where-to-get-your-key)
5656
5757
</Pitfall>
5858
59-
### Generating unique IDs for accessibility attributes {/*generating-unique-ids-for-accessibility-attributes*/}
59+
### アクセシビリティ属性のための一意の ID の生成 {/*generating-unique-ids-for-accessibility-attributes*/}
6060
61-
Call `useId` at the top level of your component to generate a unique ID:
61+
コンポーネントのトップレベルで `useId` を呼び出して、一意の ID を生成します。
6262
6363
```js [[1, 4, "passwordHintId"]]
6464
import { useId } from 'react';
@@ -68,7 +68,7 @@ function PasswordField() {
6868
// ...
6969
```
7070
71-
You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different attributes:
71+
その後、<CodeStep step={1}>生成された ID</CodeStep> をさまざまな属性に渡すことができます。
7272
7373
```js [[1, 2, "passwordHintId"], [1, 3, "passwordHintId"]]
7474
<>
@@ -77,11 +77,11 @@ You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different at
7777
</>
7878
```
7979
80-
**Let's walk through an example to see when this is useful.**
80+
**これがどのような場合に役立つかを、例を通してみてみましょう。**
8181
82-
[HTML accessibility attributes](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA) like [`aria-describedby`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby) let you specify that two tags are related to each other. For example, you can specify that an element (like an input) is described by another element (like a paragraph).
82+
[`aria-describedby`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby) のような [HTML アクセシビリティ属性](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA)を使用すると、2 つのタグが相互に関連していることを指定することができます。例えば、入力フィールドのような要素が、段落などの別の要素で説明されていることを指定することができます。
8383
84-
In regular HTML, you would write it like this:
84+
通常の HTML では、次のように記述します。
8585
8686
```html {5,8}
8787
<label>
@@ -96,7 +96,7 @@ In regular HTML, you would write it like this:
9696
</p>
9797
```
9898
99-
However, hardcoding IDs like this is not a good practice in React. A component may be rendered more than once on the page--but IDs have to be unique! Instead of hardcoding an ID, generate a unique ID with `useId`:
99+
ただし、このように ID をハードコードすることは、React ではおすすめできません。コンポーネントはページ上で複数回レンダー可能ですが、ID は一意である必要があります! ID をハードコードするのではなく、`useId` を使用して一意の ID を生成します。
100100
101101
```js {4,11,14}
102102
import { useId } from 'react';
@@ -120,7 +120,7 @@ function PasswordField() {
120120
}
121121
```
122122
123-
Now, even if `PasswordField` appears multiple times on the screen, the generated IDs won't clash.
123+
これで、画面上に `PasswordField` が複数回表示される場合でも、生成される ID が同じになることはありません。
124124
125125
<Sandpack>
126126
@@ -163,33 +163,33 @@ input { margin: 5px; }
163163
164164
</Sandpack>
165165
166-
[Watch this video](https://www.youtube.com/watch?v=0dNzNcuEuOo) to see the difference in the user experience with assistive technologies.
166+
[このビデオを見て](https://www.youtube.com/watch?v=0dNzNcuEuOo)支援技術による、ユーザ体験の違いを確認してみてください。
167167
168168
<Pitfall>
169169
170-
With [server rendering](/reference/react-dom/server), **`useId` requires an identical component tree on the server and the client**. If the trees you render on the server and the client don't match exactly, the generated IDs won't match.
170+
[サーバレンダリング](/reference/react-dom/server)では、**`useId` にはサーバとクライアント上で同一のコンポーネントツリーが必要です**。サーバ上とクライアント上でレンダーされるツリーが正確に一致しない場合、生成される ID は一致しません。
171171
172172
</Pitfall>
173173
174174
<DeepDive>
175175
176-
#### Why is useId better than an incrementing counter? {/*why-is-useid-better-than-an-incrementing-counter*/}
176+
#### useId が増分カウンタよりも良い理由 {/*why-is-useid-better-than-an-incrementing-counter*/}
177177
178-
You might be wondering why `useId` is better than incrementing a global variable like `nextId++`.
178+
`useId` `nextId++` のようなグローバル変数を増分するよりもなぜ良いのか、疑問に思われるかもしれません。
179179
180-
The primary benefit of `useId` is that React ensures that it works with [server rendering.](/reference/react-dom/server) During server rendering, your components generate HTML output. Later, on the client, [hydration](/reference/react-dom/client/hydrateRoot) attaches your event handlers to the generated HTML. For hydration to work, the client output must match the server HTML.
180+
`useId` の主な利点は、React が、[サーバレンダリング](/reference/react-dom/server)で確実に機能することを保証していることです。サーバでのレンダー中に、コンポーネントは HTML 形式の出力を生成します。その後クライアント上で、生成された HTML に、[ハイドレーション](/reference/react-dom/client/hydrateRoot)によって、イベントハンドラがアタッチされます。ハイドレーションが機能するには、クライアントの出力がサーバの HTML と一致する必要があります。
181181
182-
This is very difficult to guarantee with an incrementing counter because the order in which the client components are hydrated may not match the order in which the server HTML was emitted. By calling `useId`, you ensure that hydration will work, and the output will match between the server and the client.
182+
クライアントコンポーネントがハイドレートされる順序は、サーバ HTML が出力された順序と一致しない可能性があるため、これをインクリメントカウンタで保証することは非常に困難です。`useId` を呼び出すことで、ハイドレーションが機能し、サーバとクライアントの間で出力が一致することが保証されます。
183183
184-
Inside React, `useId` is generated from the "parent path" of the calling component. This is why, if the client and the server tree are the same, the "parent path" will match up regardless of rendering order.
184+
React 内部では、呼び出し元コンポーネントの "親のパス (parent path)" から `useId` が生成されます。そのため、クライアントとサーバのツリーが同じであれば、レンダー順序に関係なく "親のパス" が一致することになります。
185185
186186
</DeepDive>
187187
188188
---
189189
190-
### Generating IDs for several related elements {/*generating-ids-for-several-related-elements*/}
190+
### 複数の関連要素に対して ID を生成する {/*generating-ids-for-several-related-elements*/}
191191
192-
If you need to give IDs to multiple related elements, you can call `useId` to generate a shared prefix for them:
192+
複数の関連要素に ID を与える必要がある場合は、`useId` で生成した値を共有のプレフィックスとして使用できます。
193193
194194
<Sandpack>
195195
@@ -216,13 +216,13 @@ input { margin: 5px; }
216216
217217
</Sandpack>
218218
219-
This lets you avoid calling `useId` for every single element that needs a unique ID.
219+
これにより、一意の ID を必要とするすべての要素に対して `useId` を呼び出す必要がなくなります。
220220
221221
---
222222
223-
### Specifying a shared prefix for all generated IDs {/*specifying-a-shared-prefix-for-all-generated-ids*/}
223+
### 生成されるすべての ID に共有プレフィックスを指定する {/*specifying-a-shared-prefix-for-all-generated-ids*/}
224224
225-
If you render multiple independent React applications on a single page, pass `identifierPrefix` as an option to your [`createRoot`](/reference/react-dom/client/createRoot#parameters) or [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) calls. This ensures that the IDs generated by the two different apps never clash because every identifier generated with `useId` will start with the distinct prefix you've specified.
225+
複数の独立した React アプリケーションを 1 つのページにレンダーする場合は、オプションとして `identifierPrefix` [`createRoot`](/reference/react-dom/client/createRoot#parameters) または [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) に渡します。これにより、`useId` で生成されたすべての識別子が指定した個別のプレフィックスで始まるため、2 つの異なるアプリによって生成された ID が衝突することがなくなります。
226226
227227
<Sandpack>
228228

0 commit comments

Comments
 (0)