-
Notifications
You must be signed in to change notification settings - Fork 268
docs: translation for useId #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
18f7bce
docs: translation for useId
AndriP8 3201ad8
docs: update title
AndriP8 77be943
docs: make merender text to have dash and italic
AndriP8 a494d22
docs: update wording by feedback
AndriP8 a190873
docs: update render word to be italic
AndriP8 63f6c52
docs: update word server and rendering to be italic
AndriP8 246d60b
Merge branch 'main' into translate-useid
mhaidarhanif 0a0c9c7
Merge branch 'main' into translate-useid
zainfathoni 2d1dfa9
Update src/content/reference/react/useId.md
zainfathoni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,8 +4,7 @@ title: useId | |||||
|
||||||
<Intro> | ||||||
|
||||||
`useId` is a React Hook for generating unique IDs that can be passed to accessibility attributes. | ||||||
|
||||||
`useId` adalah React Hook untuk menghasilkan ID unik yang dapat diteruskan ke atribut aksesibilitas. | ||||||
```js | ||||||
const id = useId() | ||||||
``` | ||||||
|
@@ -16,11 +15,11 @@ const id = useId() | |||||
|
||||||
--- | ||||||
|
||||||
## Reference {/*reference*/} | ||||||
## Referensi {/*reference*/} | ||||||
|
||||||
### `useId()` {/*useid*/} | ||||||
|
||||||
Call `useId` at the top level of your component to generate a unique ID: | ||||||
Panggil `useId` di tingkat atas komponen Anda untuk menghasilkan ID unik: | ||||||
|
||||||
```js | ||||||
import { useId } from 'react'; | ||||||
|
@@ -30,35 +29,35 @@ function PasswordField() { | |||||
// ... | ||||||
``` | ||||||
|
||||||
[See more examples below.](#usage) | ||||||
[Lihat lebih banyak contoh di bawah ini.](#usage) | ||||||
|
||||||
#### Parameters {/*parameters*/} | ||||||
#### Parameter {/*parameters*/} | ||||||
|
||||||
`useId` does not take any parameters. | ||||||
`useId` tidak mengambil parameter apapun. | ||||||
|
||||||
#### Returns {/*returns*/} | ||||||
#### Kembalian {/*returns*/} | ||||||
|
||||||
`useId` returns a unique ID string associated with this particular `useId` call in this particular component. | ||||||
`useId` mengembalikan string ID unik yang terkait dengan panggilan `useId` tertentu dalam komponen khusus ini. | ||||||
|
||||||
#### Caveats {/*caveats*/} | ||||||
|
||||||
* `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. | ||||||
* `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 (*loop*) atau kondisi (*conditions*). Jika Anda membutuhkannya, ekstrak komponen baru dan pindahkan *state* ke dalamnya. | ||||||
zainfathoni marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
* `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) | ||||||
* `useId` **tidak boleh digunakan untuk menghasilkan *key*** dalam daftar. [*Key* harus dihasilkan dari data Anda.](/learn/rendering-lists#where-to-get-your-key) | ||||||
|
||||||
--- | ||||||
|
||||||
## Usage {/*usage*/} | ||||||
## Pengunaan {/*usage*/} | ||||||
|
||||||
<Pitfall> | ||||||
|
||||||
**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) | ||||||
**Jangan panggil `useId` untuk menghasilkan *key* dalam daftar.** [*Key* harus dihasilkan dari data Anda](/learn/rendering-lists#where-to-get-your-key) | ||||||
|
||||||
</Pitfall> | ||||||
|
||||||
### Generating unique IDs for accessibility attributes {/*generating-unique-ids-for-accessibility-attributes*/} | ||||||
### Menghasilkan ID unik untuk atribut aksesibilitas {/*generating-unique-ids-for-accessibility-attributes*/} | ||||||
|
||||||
Call `useId` at the top level of your component to generate a unique ID: | ||||||
Panggil `useId` di tingkat atas komponen Anda untuk menghasilkan ID unik: | ||||||
|
||||||
```js [[1, 4, "passwordHintId"]] | ||||||
import { useId } from 'react'; | ||||||
|
@@ -68,7 +67,7 @@ function PasswordField() { | |||||
// ... | ||||||
``` | ||||||
|
||||||
You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different attributes: | ||||||
Anda kemudian dapat meneruskan <CodeStep step={1}>ID yang dihasilkan</CodeStep> ke atribut yang berbeda: | ||||||
|
||||||
```js [[1, 2, "passwordHintId"], [1, 3, "passwordHintId"]] | ||||||
<> | ||||||
|
@@ -77,11 +76,11 @@ You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different at | |||||
</> | ||||||
``` | ||||||
|
||||||
**Let's walk through an example to see when this is useful.** | ||||||
**Mari telusuri contoh untuk melihat kapan ini berguna.** | ||||||
|
||||||
[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). | ||||||
[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`)). | ||||||
|
||||||
In regular HTML, you would write it like this: | ||||||
Dalam HTML biasa, Anda akan menulisnya seperti ini: | ||||||
|
||||||
```html {5,8} | ||||||
<label> | ||||||
|
@@ -96,7 +95,7 @@ In regular HTML, you would write it like this: | |||||
</p> | ||||||
``` | ||||||
|
||||||
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`: | ||||||
Namun, menuliskan ID secara langsung di dalam kode (*hardcoding*) seperti ini bukanlah praktik yang baik di React. Sebuah komponen dapat dirender lebih dari sekali pada halaman—namun ID harus unik! Alih-alih melakukan pemaksaan ID, buat ID unik dengan `useId`: | ||||||
mazipan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
```js {4,11,14} | ||||||
import { useId } from 'react'; | ||||||
|
@@ -120,7 +119,7 @@ function PasswordField() { | |||||
} | ||||||
``` | ||||||
|
||||||
Now, even if `PasswordField` appears multiple times on the screen, the generated IDs won't clash. | ||||||
Sekarang, meskipun `PasswordField` muncul beberapa kali di layar, ID yang dihasilkan tidak akan berbenturan. | ||||||
|
||||||
<Sandpack> | ||||||
|
||||||
|
@@ -163,33 +162,34 @@ input { margin: 5px; } | |||||
|
||||||
</Sandpack> | ||||||
|
||||||
[Watch this video](https://www.youtube.com/watch?v=0dNzNcuEuOo) to see the difference in the user experience with assistive technologies. | ||||||
[Tonton video ini](https://www.youtube.com/watch?v=0dNzNcuEuOo) untuk melihat perbedaan pengalaman pengguna dengan teknologi bantu. | ||||||
|
||||||
<Pitfall> | ||||||
|
||||||
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. | ||||||
Dengan [rendering server](/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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't fix it because the word |
||||||
|
||||||
</Pitfall> | ||||||
|
||||||
<DeepDive> | ||||||
|
||||||
#### Why is useId better than an incrementing counter? {/*why-is-useid-better-than-an-incrementing-counter*/} | ||||||
#### Mengapa useId lebih baik daripada penghitung kenaikan? {/*why-is-useid-better-than-an-incrementing-counter*/} | ||||||
|
||||||
Anda mungkin bertanya-tanya mengapa `useId` lebih baik daripada menambahkan variabel global seperti `nextId++`. | ||||||
|
||||||
You might be wondering why `useId` is better than incrementing a global variable like `nextId++`. | ||||||
Manfaat utama `useId` adalah React memastikan bahwa ia bekerja dengan [rendering server.](/reference/react-dom/server) Selama rendering server, 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 server. | ||||||
zainfathoni marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
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. | ||||||
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. | ||||||
|
||||||
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. | ||||||
|
||||||
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. | ||||||
Di dalam React, `useId` dihasilkan dari “jalur induk” dari komponen pemanggil. Inilah sebabnya, jika klien dan pohon server sama, "jalur induk" akan cocok terlepas dari urutan rendering. | ||||||
zainfathoni marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
</DeepDive> | ||||||
|
||||||
--- | ||||||
|
||||||
### Generating IDs for several related elements {/*generating-ids-for-several-related-elements*/} | ||||||
### Menghasilkan ID untuk beberapa elemen terkait {/*generating-ids-for-several-related-elements*/} | ||||||
|
||||||
If you need to give IDs to multiple related elements, you can call `useId` to generate a shared prefix for them: | ||||||
Jika Anda perlu memberikan ID ke beberapa elemen terkait, Anda dapat memanggil `useId` untuk menghasilkan awalan bersama untuk mereka: | ||||||
|
||||||
<Sandpack> | ||||||
|
||||||
|
@@ -216,13 +216,13 @@ input { margin: 5px; } | |||||
|
||||||
</Sandpack> | ||||||
|
||||||
This lets you avoid calling `useId` for every single element that needs a unique ID. | ||||||
Ini memungkinkan Anda menghindari pemanggilan `useId` untuk setiap elemen yang membutuhkan ID unik. | ||||||
|
||||||
--- | ||||||
|
||||||
### Specifying a shared prefix for all generated IDs {/*specifying-a-shared-prefix-for-all-generated-ids*/} | ||||||
### Menentukan awalan bersama untuk semua ID yang dihasilkan {/*specifying-a-shared-prefix-for-all-generated-ids*/} | ||||||
|
||||||
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. | ||||||
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. | ||||||
|
||||||
<Sandpack> | ||||||
|
||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.