-
Notifications
You must be signed in to change notification settings - Fork 267
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.
Outdated
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.
Outdated
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. | ||||||
|
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. | |
Dengan [pe-*render*-an pada *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 comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't fix it because the word pe-*render*-an
is still under discussion
zainfathoni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
zainfathoni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
zainfathoni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
zainfathoni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
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.