Skip to content

Commit 51faa81

Browse files
committed
Translate useId.md
1 parent 6cf319d commit 51faa81

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

src/content/reference/react/useId.md

Lines changed: 52 additions & 52 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` je React Hook za generisanje jedinstvenih ID-eva koji se mogu proslediti atributima pristupačnosti.
88

99
```js
1010
const id = useId()
@@ -20,7 +20,7 @@ const id = useId()
2020

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

23-
Call `useId` at the top level of your component to generate a unique ID:
23+
Pozovite `useId` na vrhu vaše komponente da biste generisali jedinstveni ID:
2424

2525
```js
2626
import { useId } from 'react';
@@ -30,39 +30,39 @@ function PasswordField() {
3030
// ...
3131
```
3232
33-
[See more examples below.](#usage)
33+
[Pogledajte još primera ispod.](#usage)
3434
35-
#### Parameters {/*parameters*/}
35+
#### Parametri {/*parameters*/}
3636
37-
`useId` does not take any parameters.
37+
`useId` ne prima nikakve parametre.
3838
39-
#### Returns {/*returns*/}
39+
#### Povratne vrednosti {/*returns*/}
4040
41-
`useId` returns a unique ID string associated with this particular `useId` call in this particular component.
41+
`useId` vraća jedinstveni ID string asociran za specifični `useId` poziv u specifičnoj komponenti.
4242
43-
#### Caveats {/*caveats*/}
43+
#### Upozorenja {/*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` je Hook, pa ga možete pozvati samo **na vrhu vaše komponente** ili vaših Hook-ova. Ne možete ga pozvati unutar petlji i uslova. Ako vam je to potrebno, izdvojite novu komponentu i pomerite state u nju.
4646
47-
* `useId` **should not be used to generate cache keys** for [use()](/reference/react/use). The ID is stable when a component is mounted but may change during rendering. Cache keys should be generated from your data.
47+
* `useId` **ne bi trebao da se koristi za generisanje keš ključeva** za [use()](/reference/react/use). ID je stabilan kada je komponenta montirana, ali se može promeniti tokom renderovanja. Trebalo bi generisati keš ključeve na osnovu vaših podataka.
4848
49-
* `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)
49+
* `useId` **ne bi trebao da se koristi za generisanje ključeva** u listi. [Ključevi trebaju biti generisani na osnovu vaših podataka.](/learn/rendering-lists#where-to-get-your-key)
5050
51-
* `useId` currently cannot be used in [async Server Components](/reference/rsc/server-components#async-components-with-server-components).
51+
* `useId` se trenutno ne može koristiti u [asinhronim Server Components](/reference/rsc/server-components#async-components-with-server-components).
5252
5353
---
5454
55-
## Usage {/*usage*/}
55+
## Upotreba {/*usage*/}
5656
5757
<Pitfall>
5858
59-
**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)
59+
**Nemojte pozivati `useId` da biste generisali ključeve u listi.** [Ključevi trebaju biti generisani na osnovu vaših podataka.](/learn/rendering-lists#where-to-get-your-key)
6060
6161
</Pitfall>
6262
63-
### Generating unique IDs for accessibility attributes {/*generating-unique-ids-for-accessibility-attributes*/}
63+
### Generisanje jedinstvenih ID-eva za atribute pristupačnosti {/*generating-unique-ids-for-accessibility-attributes*/}
6464
65-
Call `useId` at the top level of your component to generate a unique ID:
65+
Pozovite `useId` na vrhu vaše komponente da biste generisali jedinstveni ID:
6666
6767
```js [[1, 4, "passwordHintId"]]
6868
import { useId } from 'react';
@@ -72,7 +72,7 @@ function PasswordField() {
7272
// ...
7373
```
7474
75-
You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different attributes:
75+
Onda možete proslediti <CodeStep step={1}>generisani ID</CodeStep> u različite atribute:
7676
7777
```js [[1, 2, "passwordHintId"], [1, 3, "passwordHintId"]]
7878
<>
@@ -81,26 +81,26 @@ You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different at
8181
</>
8282
```
8383
84-
**Let's walk through an example to see when this is useful.**
84+
**Prođimo kroz primer da vidimo kada je ovo korisno.**
8585
86-
[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).
86+
[HTML atributi pristupačnosti](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA) kao što je [`aria-describedby`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby) vam omogućavaju da specificirate dva tag-a koja su povezana. Na primer, možete specificirati da je element (kao što je input) opisan drugim elementom (kao što je paragraph).
8787
88-
In regular HTML, you would write it like this:
88+
U običnom HTML-u napisali biste ovako nešto:
8989
9090
```html {5,8}
9191
<label>
92-
Password:
92+
Šifra:
9393
<input
9494
type="password"
9595
aria-describedby="password-hint"
9696
/>
9797
</label>
9898
<p id="password-hint">
99-
The password should contain at least 18 characters
99+
Šifra treba da sadrži barem 18 karaktera
100100
</p>
101101
```
102102
103-
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`:
103+
Međutim, hardkodirani ID-evi poput ovih nisu dobra praksa u React-u. Komponenta može biti renderovana više od jednom na stranici--ali ID-evi moraju biti jedinstveni! Umesto da hardkodirate ID, generišite jedinstveni ID sa `useId`:
104104
105105
```js {4,11,14}
106106
import { useId } from 'react';
@@ -110,21 +110,21 @@ function PasswordField() {
110110
return (
111111
<>
112112
<label>
113-
Password:
113+
Šifra:
114114
<input
115115
type="password"
116116
aria-describedby={passwordHintId}
117117
/>
118118
</label>
119119
<p id={passwordHintId}>
120-
The password should contain at least 18 characters
120+
Šifra treba da sadrži barem 18 karaktera
121121
</p>
122122
</>
123123
);
124124
}
125125
```
126126
127-
Now, even if `PasswordField` appears multiple times on the screen, the generated IDs won't clash.
127+
Sada, čak iako se `PasswordField` pojavi više puta na ekranu, generisani ID-evi se neće preklapati.
128128
129129
<Sandpack>
130130
@@ -136,14 +136,14 @@ function PasswordField() {
136136
return (
137137
<>
138138
<label>
139-
Password:
139+
Šifra:
140140
<input
141141
type="password"
142142
aria-describedby={passwordHintId}
143143
/>
144144
</label>
145145
<p id={passwordHintId}>
146-
The password should contain at least 18 characters
146+
Šifra treba da sadrži barem 18 karaktera
147147
</p>
148148
</>
149149
);
@@ -152,9 +152,9 @@ function PasswordField() {
152152
export default function App() {
153153
return (
154154
<>
155-
<h2>Choose password</h2>
155+
<h2>Unesi šifru</h2>
156156
<PasswordField />
157-
<h2>Confirm password</h2>
157+
<h2>Potvrdi šifru</h2>
158158
<PasswordField />
159159
</>
160160
);
@@ -167,33 +167,33 @@ input { margin: 5px; }
167167
168168
</Sandpack>
169169
170-
[Watch this video](https://www.youtube.com/watch?v=0dNzNcuEuOo) to see the difference in the user experience with assistive technologies.
170+
[Pogledajte ovaj video](https://www.youtube.com/watch?v=0dNzNcuEuOo) da biste uočili razliku u korisničkom iskustvu sa pomoćnim tehnologijama.
171171
172172
<Pitfall>
173173
174-
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.
174+
Sa [renderovanjem na serveru](/reference/react-dom/server), **`useId` zahteva identično stablo komponente na serveru i na klijentu**. Ako se stabla koja renderujete na serveru i klijentu ne poklapaju, ni generisani ID-evi se neće poklapati.
175175
176176
</Pitfall>
177177
178178
<DeepDive>
179179
180-
#### Why is useId better than an incrementing counter? {/*why-is-useid-better-than-an-incrementing-counter*/}
180+
#### Zašto je useId bolji od inkrementalnog brojača? {/*why-is-useid-better-than-an-incrementing-counter*/}
181181
182-
You might be wondering why `useId` is better than incrementing a global variable like `nextId++`.
182+
Možda se pitate zašto je `useId` bolji od inkrementiranja globalne promenljive poput `nextId++`.
183183
184-
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.
184+
Primarna korist od `useId` je da React garantuje da radi sa [renderovanjem na serveru](/reference/react-dom/server). Tokom renderovanja na serveru, vaše komponente generišu HTML izlaz. Kasnije, na klijentu, [hidratacijom](/reference/react-dom/client/hydrateRoot) se povezuju vaši event handler-i sa generisanim HTML-om. Da bi hidratacija radila, klijentski izlaz se mora poklapati sa serverskim HTML-om.
185185
186-
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.
186+
Ovo je teško garantovati sa inkrementalnim brojačem jer se redosled u kom se Client Components hidratizuju možda neće poklapati sa redosledom u kom je emitovan HTML sa servera. Pozivanjem `useId` osiguravate da će hidratacija raditi i da će se izlaz servera poklapati sa klijentskim.
187187
188-
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.
188+
Unutar React-a, `useId` je generisan na osnovu "roditeljske putanje" pozivajuće komponente. Zbog toga, ako se klijentsko i serversko stablo poklapaju, "roditeljska putanja" će se poklapati bez obzira na redosled.
189189
190190
</DeepDive>
191191
192192
---
193193
194-
### Generating IDs for several related elements {/*generating-ids-for-several-related-elements*/}
194+
### Generisanje ID-eva za više povezanih elemenata {/*generating-ids-for-several-related-elements*/}
195195
196-
If you need to give IDs to multiple related elements, you can call `useId` to generate a shared prefix for them:
196+
Ako vam je potrebno da napravite ID-eve za više povezanih elemenata, možete pozvati `useId` da generišete deljeni prefiks za njih:
197197
198198
<Sandpack>
199199
@@ -204,10 +204,10 @@ export default function Form() {
204204
const id = useId();
205205
return (
206206
<form>
207-
<label htmlFor={id + '-firstName'}>First Name:</label>
207+
<label htmlFor={id + '-firstName'}>Ime:</label>
208208
<input id={id + '-firstName'} type="text" />
209209
<hr />
210-
<label htmlFor={id + '-lastName'}>Last Name:</label>
210+
<label htmlFor={id + '-lastName'}>Prezime:</label>
211211
<input id={id + '-lastName'} type="text" />
212212
</form>
213213
);
@@ -220,13 +220,13 @@ input { margin: 5px; }
220220
221221
</Sandpack>
222222
223-
This lets you avoid calling `useId` for every single element that needs a unique ID.
223+
Ovo vam omogućava da izbegnete pozivanje `useId`-a za svaki pojedinačni element kojem je potreban jedinstveni ID.
224224
225225
---
226226
227-
### Specifying a shared prefix for all generated IDs {/*specifying-a-shared-prefix-for-all-generated-ids*/}
227+
### Specificiranje deljenog prefiksa za sve generisane ID-eve {/*specifying-a-shared-prefix-for-all-generated-ids*/}
228228
229-
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.
229+
Ako renderujete više nezavisnih React aplikacija na jednog stranici, prosledite `identifierPrefix` u vaše [`createRoot`](/reference/react-dom/client/createRoot#parameters) ili [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) pozive. Ovo osigurava da se ID-evi generisani u dve različite aplikacije nikad neće preklapati jer će svaki identifikator generisan sa `useId` početi sa različitim prefiksom koji ste specificirali.
230230
231231
<Sandpack>
232232
@@ -246,18 +246,18 @@ import { useId } from 'react';
246246

247247
function PasswordField() {
248248
const passwordHintId = useId();
249-
console.log('Generated identifier:', passwordHintId)
249+
console.log('Generisani identifikator:', passwordHintId)
250250
return (
251251
<>
252252
<label>
253-
Password:
253+
Šifra:
254254
<input
255255
type="password"
256256
aria-describedby={passwordHintId}
257257
/>
258258
</label>
259259
<p id={passwordHintId}>
260-
The password should contain at least 18 characters
260+
Šifra treba da sadrži barem 18 karaktera
261261
</p>
262262
</>
263263
);
@@ -266,7 +266,7 @@ function PasswordField() {
266266
export default function App() {
267267
return (
268268
<>
269-
<h2>Choose password</h2>
269+
<h2>Unesi šifru</h2>
270270
<PasswordField />
271271
</>
272272
);
@@ -309,9 +309,9 @@ input { margin: 5px; }
309309
310310
---
311311
312-
### Using the same ID prefix on the client and the server {/*using-the-same-id-prefix-on-the-client-and-the-server*/}
312+
### Upotreba istog ID prefiksa na klijentu i serveru {/*using-the-same-id-prefix-on-the-client-and-the-server*/}
313313
314-
If you [render multiple independent React apps on the same page](#specifying-a-shared-prefix-for-all-generated-ids), and some of these apps are server-rendered, make sure that the `identifierPrefix` you pass to the [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) call on the client side is the same as the `identifierPrefix` you pass to the [server APIs](/reference/react-dom/server) such as [`renderToPipeableStream`.](/reference/react-dom/server/renderToPipeableStream)
314+
Ako [renderujete više nezavisnih React aplikacija na istoj stranici](#specifying-a-shared-prefix-for-all-generated-ids), a neke od tih aplikacija su renderovane na serveru, postarajte se da `identifierPrefix` koji prosleđujete u [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) poziv na klijentskoj strani bude isti kao i `identifierPrefix` koji prosleđujete u [serverske API-je](/reference/react-dom/server) poput [`renderToPipeableStream`](/reference/react-dom/server/renderToPipeableStream).
315315
316316
```js
317317
// Server
@@ -324,7 +324,7 @@ const { pipe } = renderToPipeableStream(
324324
```
325325
326326
```js
327-
// Client
327+
// Klijent
328328
import { hydrateRoot } from 'react-dom/client';
329329

330330
const domNode = document.getElementById('root');
@@ -335,4 +335,4 @@ const root = hydrateRoot(
335335
);
336336
```
337337
338-
You do not need to pass `identifierPrefix` if you only have one React app on the page.
338+
Nije potrebno da prosleđujete `identifierPrefix` ako imate samo jednu React aplikaciju na stranici.

0 commit comments

Comments
 (0)