Skip to content

Commit 49a97ac

Browse files
AndriP8mhaidarhanifzainfathoni
authored
docs: translation for useId (#524)
Co-authored-by: M Haidar Hanif <git@mhaidarhanif.com> Co-authored-by: Zain Fathoni <me@zainf.dev> Co-authored-by: Zain Fathoni <zain.fathoni@gmail.com>
1 parent 1f7fd07 commit 49a97ac

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,8 +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.
8-
7+
`useId` adalah React Hook untuk menghasilkan ID unik yang dapat diteruskan ke atribut aksesibilitas.
98
```js
109
const id = useId()
1110
```
@@ -16,11 +15,11 @@ const id = useId()
1615

1716
---
1817

19-
## Reference {/*reference*/}
18+
## Referensi {/*reference*/}
2019

2120
### `useId()` {/*useid*/}
2221

23-
Call `useId` at the top level of your component to generate a unique ID:
22+
Panggil `useId` di tingkat teratas komponen Anda untuk menghasilkan ID unik:
2423

2524
```js
2625
import { useId } from 'react';
@@ -30,35 +29,35 @@ function PasswordField() {
3029
// ...
3130
```
3231
33-
[See more examples below.](#usage)
32+
[Lihat lebih banyak contoh di bawah ini.](#usage)
3433
35-
#### Parameters {/*parameters*/}
34+
#### Parameter {/*parameters*/}
3635
37-
`useId` does not take any parameters.
36+
`useId` tidak mengambil parameter apapun.
3837
39-
#### Returns {/*returns*/}
38+
#### Kembalian {/*returns*/}
4039
41-
`useId` returns a unique ID string associated with this particular `useId` call in this particular component.
40+
`useId` mengembalikan string ID unik yang terkait dengan panggilan `useId` tertentu dalam komponen khusus ini.
4241
4342
#### Caveats {/*caveats*/}
4443
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.
44+
* `useId` adalah sebuah Hook, jadi Anda hanya dapat memanggilnya **di tingkat teratas komponen Anda** atau Hook Anda sendiri. Anda tidak dapat memanggilnya di dalam perulangan (*loops*) atau kondisi (*conditions*). Jika Anda membutuhkannya, ekstrak komponen baru dan pindahkan *state* ke dalamnya.
4645
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)
46+
* `useId` **tidak boleh digunakan untuk menghasilkan *key*** dalam daftar. [*Key* harus dihasilkan dari data Anda.](/learn/rendering-lists#where-to-get-your-key)
4847
4948
---
5049
51-
## Usage {/*usage*/}
50+
## Pengunaan {/*usage*/}
5251
5352
<Pitfall>
5453
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)
54+
**Jangan panggil `useId` untuk menghasilkan *key* dalam daftar.** [*Key* harus dihasilkan dari data Anda](/learn/rendering-lists#where-to-get-your-key)
5655
5756
</Pitfall>
5857
59-
### Generating unique IDs for accessibility attributes {/*generating-unique-ids-for-accessibility-attributes*/}
58+
### Menghasilkan ID unik untuk atribut aksesibilitas {/*generating-unique-ids-for-accessibility-attributes*/}
6059
61-
Call `useId` at the top level of your component to generate a unique ID:
60+
Panggil `useId` di tingkat atas komponen Anda untuk menghasilkan ID unik:
6261
6362
```js [[1, 4, "passwordHintId"]]
6463
import { useId } from 'react';
@@ -68,7 +67,7 @@ function PasswordField() {
6867
// ...
6968
```
7069
71-
You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different attributes:
70+
Anda kemudian dapat meneruskan <CodeStep step={1}>ID yang dihasilkan</CodeStep> ke atribut yang berbeda:
7271
7372
```js [[1, 2, "passwordHintId"], [1, 3, "passwordHintId"]]
7473
<>
@@ -77,11 +76,11 @@ You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different at
7776
</>
7877
```
7978
80-
**Let's walk through an example to see when this is useful.**
79+
**Mari telusuri contoh untuk melihat kapan ini berguna.**
8180
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).
81+
[Atribut aksesibilitas HTML](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA) seperti [`aria-describedby`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby) membiarkan Anda menentukan bahwa dua *tag* terkait satu sama lain. Misalnya, Anda dapat menentukan bahwa suatu elemen (seperti sebuah masukan (`input`)) dijelaskan oleh elemen lain (seperti sebuah paragraf (`p`)).
8382
84-
In regular HTML, you would write it like this:
83+
Dalam HTML biasa, Anda akan menulisnya seperti ini:
8584
8685
```html {5,8}
8786
<label>
@@ -96,7 +95,7 @@ In regular HTML, you would write it like this:
9695
</p>
9796
```
9897
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`:
98+
Namun, menuliskan ID secara langsung di dalam kode (*hardcoding*) seperti ini bukanlah praktik yang baik di React. Sebuah komponen dapat di-*render* lebih dari sekali pada halaman—namun ID harus unik! Alih-alih melakukan pemaksaan ID, buat ID unik dengan `useId`:
10099
101100
```js {4,11,14}
102101
import { useId } from 'react';
@@ -120,7 +119,7 @@ function PasswordField() {
120119
}
121120
```
122121
123-
Now, even if `PasswordField` appears multiple times on the screen, the generated IDs won't clash.
122+
Sekarang, meskipun `PasswordField` muncul beberapa kali di layar, ID yang dihasilkan tidak akan berbenturan.
124123
125124
<Sandpack>
126125
@@ -163,33 +162,34 @@ input { margin: 5px; }
163162
164163
</Sandpack>
165164
166-
[Watch this video](https://www.youtube.com/watch?v=0dNzNcuEuOo) to see the difference in the user experience with assistive technologies.
165+
[Tonton video ini](https://www.youtube.com/watch?v=0dNzNcuEuOo) untuk melihat perbedaan pengalaman pengguna dengan teknologi bantu.
167166
168167
<Pitfall>
169168
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.
169+
Dengan [*server rendering*](/reference/react-dom/server), **`useId` membutuhkan pohon komponen yang identik di *server* dan klien**. Jika pohon yang Anda *render* di *server* dan klien tidak sama persis, ID yang dihasilkan tidak akan cocok.
171170
172171
</Pitfall>
173172
174173
<DeepDive>
175174
176-
#### Why is useId better than an incrementing counter? {/*why-is-useid-better-than-an-incrementing-counter*/}
175+
#### Mengapa useId lebih baik daripada penghitung kenaikan? {/*why-is-useid-better-than-an-incrementing-counter*/}
176+
177+
Anda mungkin bertanya-tanya mengapa `useId` lebih baik daripada menambahkan variabel global seperti `nextId++`.
177178
178-
You might be wondering why `useId` is better than incrementing a global variable like `nextId++`.
179+
Manfaat utama `useId` adalah React memastikan bahwa ia bekerja dengan [*server rendering*.](/reference/react-dom/server) Selama *server rendering*, komponen Anda menghasilkan keluaran HTML. Kemudian, pada klien, [hidrasi](/reference/react-dom/client/hydrateRoot) melampirkan *event handler* Anda ke HTML yang dihasilkan. Agar hidrasi berfungsi, output klien harus cocok dengan HTML dari *server*.
179180
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.
181+
Hal ini sangat sulit untuk dijamin dengan penghitung kenaikan karena urutan di mana komponen klien terhidrasi mungkin tidak sesuai dengan urutan di mana HTML dari *server* dipancarkan. Dengan memanggil `useId`, Anda memastikan bahwa hidrasi akan berfungsi, dan hasilnya akan cocok antara *server* dan klien.
181182
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.
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+
Di dalam React, `useId` dihasilkan dari “jalur induk” dari komponen pemanggil. Inilah sebabnya, jika pohon di klien dan *server* sama, "jalur induk" akan cocok terlepas dari urutan *rendering*.
185185
186186
</DeepDive>
187187
188188
---
189189
190-
### Generating IDs for several related elements {/*generating-ids-for-several-related-elements*/}
190+
### Menghasilkan ID untuk beberapa elemen terkait {/*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+
Jika Anda perlu memberikan ID ke beberapa elemen terkait, Anda dapat memanggil `useId` untuk menghasilkan awalan bersama untuk mereka:
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+
Ini memungkinkan Anda menghindari pemanggilan `useId` untuk setiap elemen yang membutuhkan ID unik.
220220
221221
---
222222
223-
### Specifying a shared prefix for all generated IDs {/*specifying-a-shared-prefix-for-all-generated-ids*/}
223+
### Menentukan awalan bersama untuk semua ID yang dihasilkan {/*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+
Jika Anda me-*render* beberapa aplikasi React independen pada satu halaman, berikan `identifierPrefix` sebagai opsi untuk panggilan [`createRoot`](/reference/react-dom/client/createRoot#parameters) atau [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) Anda. Hal ini memastikan bahwa ID yang dihasilkan oleh dua aplikasi berbeda tidak pernah berbenturan karena setiap pengenal yang dibuat dengan `useId` akan dimulai dengan awalan berbeda yang telah Anda tentukan.
226226
227227
<Sandpack>
228228

0 commit comments

Comments
 (0)