Skip to content

Commit f03c477

Browse files
authored
Merge pull request #120 from reactjs/features/render-and-commit
Translate render-and-commit.md
2 parents 6c2149d + fa01157 commit f03c477

File tree

2 files changed

+62
-62
lines changed

2 files changed

+62
-62
lines changed

src/content/learn/adding-interactivity.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,18 @@ Pročitajte **[State: Memorija Component-e](/learn/state-a-components-memory)**
235235

236236
## Render i commit {/*render-and-commit*/}
237237

238-
Pre nego što se vaše component-e prikažu na ekranu, React mora da ih render-uje. Razumevanje koraka u ovom procesu pomoći će vam da razmislite o tome kako se vaš kod izvršava i da objasnite njegovo ponašanje.
238+
Pre nego što se vaše component-e prikažu na ekranu, React mora da ih renderuje. Razumevanje koraka u ovom procesu pomoći će vam da razmislite o tome kako se vaš kod izvršava i da objasnite njegovo ponašanje.
239239

240-
Zamislite da su vaše component-e kuvari u kuhinji, koji pripremaju ukusna jela od sastojaka. U ovom scenariju, React je konobar koji prenosi narudžbine od gostiju i donosi im njihova jela. Ovaj proces naručivanja i posluživanja UI-a ima tri koraka:
240+
Zamislite da su vaše component-e kuvari u kuhinji, koji pripremaju ukusna jela od sastojaka. U ovom scenariju, React je konobar koji prenosi porudžbine od gostiju i donosi im njihova jela. Ovaj proces poručivanja i posluživanja UI-a ima tri koraka:
241241

242-
1. **Pokretanje** render-a (prenos narudžbine gosta u kuhinju)
243-
2. **Render-ovanje** component-e (priprema narudžbine u kuhinji)
244-
3. **Commit-ovanje** u DOM (postavljanje narudžbine na sto)
242+
1. **Pokretanje** rendera (prenos porudžbine gosta u kuhinju)
243+
2. **Renderovanje** component-e (priprema porudžbine u kuhinji)
244+
3. **Commit-ovanje** u DOM (postavljanje porudžbine na sto)
245245

246246
<IllustrationBlock sequential>
247-
<Illustration caption="Trigger" alt="React kao konobar u restoranu, prenosi narudžbine od korisnika i dostavlja ih u Component-u Kitchen." src="/images/docs/illustrations/i_render-and-commit1.png" />
247+
<Illustration caption="Pokretanje" alt="React kao konobar u restoranu, prenosi porudžbine od korisnika i dostavlja ih u Kitchen Component-u." src="/images/docs/illustrations/i_render-and-commit1.png" />
248248
<Illustration caption="Render" alt="Šef kuhinje za Card daje React-u svežu Card component-u." src="/images/docs/illustrations/i_render-and-commit2.png" />
249-
<Illustration caption="Commit" alt="React donosi Card korisniku za njihov sto." src="/images/docs/illustrations/i_render-and-commit3.png" />
249+
<Illustration caption="Commit" alt="React donosi Card korisniku za njegov sto." src="/images/docs/illustrations/i_render-and-commit3.png" />
250250
</IllustrationBlock>
251251

252252
<LearnMore path="/learn/render-and-commit">

src/content/learn/render-and-commit.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
---
2-
title: Render and Commit
2+
title: Render i Commit
33
---
44

55
<Intro>
66

7-
Before your components are displayed on screen, they must be rendered by React. Understanding the steps in this process will help you think about how your code executes and explain its behavior.
7+
Pre nego što se vaše komponente prikažu na ekranu, React mora da ih renderuje. Razumevanje koraka u ovom procesu pomoći će vam da razmislite o tome kako se vaš kod izvršava i da objasnite njegovo ponašanje.
88

99
</Intro>
1010

1111
<YouWillLearn>
1212

13-
* What rendering means in React
14-
* When and why React renders a component
15-
* The steps involved in displaying a component on screen
16-
* Why rendering does not always produce a DOM update
13+
* Šta u React-u znači renderovanje
14+
* Kada i zašto React renderuje komponentu
15+
* Korake potrebne za prikaz komponente na ekranu
16+
* Zašto renderovanje ne ažurira DOM uvek
1717

1818
</YouWillLearn>
1919

20-
Imagine that your components are cooks in the kitchen, assembling tasty dishes from ingredients. In this scenario, React is the waiter who puts in requests from customers and brings them their orders. This process of requesting and serving UI has three steps:
20+
Zamislite da su vaše komponente kuvari u kuhinji, koji pripremaju ukusna jela od sastojaka. U ovom scenariju, React je konobar koji prenosi porudžbine od gostiju i donosi im njihova jela. Ovaj proces poručivanja i posluživanja UI-a ima tri koraka:
2121

22-
1. **Triggering** a render (delivering the guest's order to the kitchen)
23-
2. **Rendering** the component (preparing the order in the kitchen)
24-
3. **Committing** to the DOM (placing the order on the table)
22+
1. **Pokretanje** rendera (prenos porudžbine gosta u kuhinju)
23+
2. **Renderovanje** komponente (priprema porudžbine u kuhinji)
24+
3. **Commit-ovanje** u DOM (postavljanje porudžbine na sto)
2525

2626
<IllustrationBlock sequential>
27-
<Illustration caption="Trigger" alt="React as a server in a restaurant, fetching orders from the users and delivering them to the Component Kitchen." src="/images/docs/illustrations/i_render-and-commit1.png" />
28-
<Illustration caption="Render" alt="The Card Chef gives React a fresh Card component." src="/images/docs/illustrations/i_render-and-commit2.png" />
29-
<Illustration caption="Commit" alt="React delivers the Card to the user at their table." src="/images/docs/illustrations/i_render-and-commit3.png" />
27+
<Illustration caption="Pokretanje" alt="React kao konobar u restoranu, prenosi porudžbine od korisnika i dostavlja ih u Kitchen komponentu." src="/images/docs/illustrations/i_render-and-commit1.png" />
28+
<Illustration caption="Render" alt="Šef kuhinje za Card daje React-u svežu Card komponentu." src="/images/docs/illustrations/i_render-and-commit2.png" />
29+
<Illustration caption="Commit" alt="React donosi Card korisniku za njegov sto." src="/images/docs/illustrations/i_render-and-commit3.png" />
3030
</IllustrationBlock>
3131

32-
## Step 1: Trigger a render {/*step-1-trigger-a-render*/}
32+
## Korak 1: Pokrenuti render {/*step-1-trigger-a-render*/}
3333

34-
There are two reasons for a component to render:
34+
Postoje dva razloga da se komponenta renderuje:
3535

36-
1. It's the component's **initial render.**
37-
2. The component's (or one of its ancestors') **state has been updated.**
36+
1. **Inicijalni render** komponente.
37+
2. **State se promenio**, bilo od komponente ili nekog od njenih roditelja.
3838

39-
### Initial render {/*initial-render*/}
39+
### Inicijalni render {/*initial-render*/}
4040

41-
When your app starts, you need to trigger the initial render. Frameworks and sandboxes sometimes hide this code, but it's done by calling [`createRoot`](/reference/react-dom/client/createRoot) with the target DOM node, and then calling its `render` method with your component:
41+
Kad se aplikacija pokrene, morate započeti inicijalni render. Framework-ovi i sandbox-ovi često skrivaju ovaj kod, ali se on pokreće pozivanjem [`createRoot`](/reference/react-dom/client/createRoot) nad željenim DOM čvorom, a nakon toga i pozivanjem `render` metode sa vašom komponentom:
4242

4343
<Sandpack>
4444

@@ -55,44 +55,44 @@ export default function Image() {
5555
return (
5656
<img
5757
src="https://i.imgur.com/ZF6s192.jpg"
58-
alt="'Floralis Genérica' by Eduardo Catalano: a gigantic metallic flower sculpture with reflective petals"
58+
alt="'Floralis Genérica' napravio Eduardo Catalano: ogromna metalik skulptura cveta sa reflektujućim laticama"
5959
/>
6060
);
6161
}
6262
```
6363

6464
</Sandpack>
6565

66-
Try commenting out the `root.render()` call and see the component disappear!
66+
Zakomentarišite `root.render()` poziv i vidite kako će komponenta nestati!
6767

68-
### Re-renders when state updates {/*re-renders-when-state-updates*/}
68+
### Ponovni renderi kad se state ažurira {/*re-renders-when-state-updates*/}
6969

70-
Once the component has been initially rendered, you can trigger further renders by updating its state with the [`set` function.](/reference/react/useState#setstate) Updating your component's state automatically queues a render. (You can imagine these as a restaurant guest ordering tea, dessert, and all sorts of things after putting in their first order, depending on the state of their thirst or hunger.)
70+
Kada je komponenta inicijalno renderovana, možete pokrenuti naredne rendere ažuriranjem state-a pomoću [`set` funkcije](/reference/react/useState#setstate). Ažuriranjem state-a vaše komponente automatski stavljate render u red čekanja. (Ovo možete zamisliti kao da gost restorana poručuje čaj, dezert i ostale stvari nakon prve porudžbine, u zavisnosti od state-a žeđi i gladi.)
7171

7272
<IllustrationBlock sequential>
73-
<Illustration caption="State update..." alt="React as a server in a restaurant, serving a Card UI to the user, represented as a patron with a cursor for their head. They patron expresses they want a pink card, not a black one!" src="/images/docs/illustrations/i_rerender1.png" />
74-
<Illustration caption="...triggers..." alt="React returns to the Component Kitchen and tells the Card Chef they need a pink Card." src="/images/docs/illustrations/i_rerender2.png" />
75-
<Illustration caption="...render!" alt="The Card Chef gives React the pink Card." src="/images/docs/illustrations/i_rerender3.png" />
73+
<Illustration caption="Ažuriranje state-a..." alt="React kao konobar u restoranu, servira Card UI korisniku, koji je predstavljen kao čovek sa kursorom na glavi. Korisnik izražava da želi roze karticu, a ne crnu!" src="/images/docs/illustrations/i_rerender1.png" />
74+
<Illustration caption="...pokreće..." alt="React se vraća u Kitchen komponentu i kaže šefu kuhinje za Card da mu treba roze Card." src="/images/docs/illustrations/i_rerender2.png" />
75+
<Illustration caption="...render!" alt="Šef kuhinje za Card daje React-u roze Card." src="/images/docs/illustrations/i_rerender3.png" />
7676
</IllustrationBlock>
7777

78-
## Step 2: React renders your components {/*step-2-react-renders-your-components*/}
78+
## Korak 2: React renderuje vaše komponente {/*step-2-react-renders-your-components*/}
7979

80-
After you trigger a render, React calls your components to figure out what to display on screen. **"Rendering" is React calling your components.**
80+
Kada pokrenete render, React poziva vaše komponente da shvati šta da prikaže na ekranu. **"Renderovanje" je zapravo React-ovo pozivanje vaših komponenata.**
8181

82-
* **On initial render,** React will call the root component.
83-
* **For subsequent renders,** React will call the function component whose state update triggered the render.
82+
* **Pri inicijalnom renderu**, React će pozvati root komponentu.
83+
* **Za naredne rendere**, React će pozvati funkciju komponente čije ažuriranje state-a je pokrenulo render.
8484

85-
This process is recursive: if the updated component returns some other component, React will render _that_ component next, and if that component also returns something, it will render _that_ component next, and so on. The process will continue until there are no more nested components and React knows exactly what should be displayed on screen.
85+
Ovaj proces je rekurzivan: ako ažurirana komponenta vrati drugu komponentu, React će renderovati _tu drugu_ komponentu, a ako ta komponenta takođe nešto vrati, renderovaće _to nešto_ sledeće, i tako dalje. Proces će se nastaviti dok god postoje ugnježdene komponente i React zna tačno šta treba biti prikazano na ekranu.
8686

87-
In the following example, React will call `Gallery()` and `Image()` several times:
87+
U narednom primeru, React će pozvati `Gallery()` i `Image()` nekoliko puta:
8888

8989
<Sandpack>
9090

9191
```js src/Gallery.js active
9292
export default function Gallery() {
9393
return (
9494
<section>
95-
<h1>Inspiring Sculptures</h1>
95+
<h1>Inspirativne skulpture</h1>
9696
<Image />
9797
<Image />
9898
<Image />
@@ -104,7 +104,7 @@ function Image() {
104104
return (
105105
<img
106106
src="https://i.imgur.com/ZF6s192.jpg"
107-
alt="'Floralis Genérica' by Eduardo Catalano: a gigantic metallic flower sculpture with reflective petals"
107+
alt="'Floralis Genérica' napravio Eduardo Catalano: ogromna metalik skulptura cveta sa reflektujućim laticama"
108108
/>
109109
);
110110
}
@@ -124,36 +124,36 @@ img { margin: 0 10px 10px 0; }
124124

125125
</Sandpack>
126126

127-
* **During the initial render,** React will [create the DOM nodes](https://developer.mozilla.org/docs/Web/API/Document/createElement) for `<section>`, `<h1>`, and three `<img>` tags.
128-
* **During a re-render,** React will calculate which of their properties, if any, have changed since the previous render. It won't do anything with that information until the next step, the commit phase.
127+
* **Tokom inicijalnog rendera** React će [kreirati DOM čvorove](https://developer.mozilla.org/docs/Web/API/Document/createElement) za `<section>`, `<h1>` i tri `<img>` tag-a.
128+
* **Tokom ponovnog rendera** React će izračunati koja od njihovih polja (ili nijedno) su se promenila od prethodnog rendera. Neće uraditi ništa sa tom informacijom do narednog koraka, commit faze.
129129

130130
<Pitfall>
131131

132-
Rendering must always be a [pure calculation](/learn/keeping-components-pure):
132+
Renderovanje mora uvek biti [čist proračun](/learn/keeping-components-pure):
133133

134-
* **Same inputs, same output.** Given the same inputs, a component should always return the same JSX. (When someone orders a salad with tomatoes, they should not receive a salad with onions!)
135-
* **It minds its own business.** It should not change any objects or variables that existed before rendering. (One order should not change anyone else's order.)
134+
* **Isti input-i, isti rezultat.** Dobijanjem istih input-a, komponenta treba uvek da vrati isti JSX. (Kada neko poruči salatu sa paradajzom, ne bi trebao da dobije salatu sa lukom!)
135+
* **Gleda samo svoja posla.** Ne bi trebalo da menja nikakve objekte ili promenljive koji su postojali pre renderovanja. (Jedna porudžbina ne bi trebala da menja bilo koju drugu porudžbinu.)
136136

137-
Otherwise, you can encounter confusing bugs and unpredictable behavior as your codebase grows in complexity. When developing in "Strict Mode", React calls each component's function twice, which can help surface mistakes caused by impure functions.
137+
U suprotnom, naići ćete na zbunjujuće bug-ove i nepredvidivo ponašanje dok se kompleksnost na vašem projektu povećava. U toku razvoja sa "Strict Mode", React poziva funkciju svake komponente dvaput, što može pomoći da se uoče greške prouzrokovane nečistim funkcijama.
138138

139139
</Pitfall>
140140

141141
<DeepDive>
142142

143-
#### Optimizing performance {/*optimizing-performance*/}
143+
#### Optimizacija performansi {/*optimizing-performance*/}
144144

145-
The default behavior of rendering all components nested within the updated component is not optimal for performance if the updated component is very high in the tree. If you run into a performance issue, there are several opt-in ways to solve it described in the [Performance](https://reactjs.org/docs/optimizing-performance.html) section. **Don't optimize prematurely!**
145+
Default ponašanje renderovanja svih komponenti ugnježdenih u ažuriranu komponentu nije optimalno za performanse ako je ažurirana komponenta dosta visoko u stablu. Ako naiđete na problem sa performansama, postoji nekoliko opcija da to rešite opisanih u sekciji [Performanse](https://reactjs.org/docs/optimizing-performance.html). **Nemojte optimizovati prerano!**
146146

147147
</DeepDive>
148148

149-
## Step 3: React commits changes to the DOM {/*step-3-react-commits-changes-to-the-dom*/}
149+
## Korak 3: React commit-uje promene na DOM {/*step-3-react-commits-changes-to-the-dom*/}
150150

151-
After rendering (calling) your components, React will modify the DOM.
151+
Nakon renderovanja (pozivanja) vaših komponenata, React će izmeniti DOM.
152152

153-
* **For the initial render,** React will use the [`appendChild()`](https://developer.mozilla.org/docs/Web/API/Node/appendChild) DOM API to put all the DOM nodes it has created on screen.
154-
* **For re-renders,** React will apply the minimal necessary operations (calculated while rendering!) to make the DOM match the latest rendering output.
153+
* **Za inicijalni render**, React će koristiti [`appendChild()`](https://developer.mozilla.org/docs/Web/API/Node/appendChild) DOM API da postavi sve DOM čvorove koje je kreirao na ekran.
154+
* **Za ponovne rendere**, React će primeniti minimum neophodnih operacija (izračunatih tokom renderovanja!) da bi učinio da se DOM poklapa sa najnovijim rezultatom renderovanja.
155155

156-
**React only changes the DOM nodes if there's a difference between renders.** For example, here is a component that re-renders with different props passed from its parent every second. Notice how you can add some text into the `<input>`, updating its `value`, but the text doesn't disappear when the component re-renders:
156+
**React menja DOM čvorove samo ako postoji razlika između rendera.** Na primer, ovde je komponenta koja se ponovo renderuje sa drugačijim props-ima koje dobija od roditelja svake sekunde. Primetite da možete dodati tekst u `<input>`, menjajući `value`, i da taj tekst neće nestati kad se komponenta ponovo renderuje:
157157

158158
<Sandpack>
159159

@@ -193,21 +193,21 @@ export default function App() {
193193

194194
</Sandpack>
195195

196-
This works because during this last step, React only updates the content of `<h1>` with the new `time`. It sees that the `<input>` appears in the JSX in the same place as last time, so React doesn't touch the `<input>`or its `value`!
197-
## Epilogue: Browser paint {/*epilogue-browser-paint*/}
196+
Ovo radi jer tokom poslednjeg koraka, React jedino ažurira sadržaj `<h1>` sa novim `time`. On vidi da se `<input>` pojavljuje u JSX-u na istom mestu kao prethodni put, pa React ne dira `<input>`niti njegov `value`!
197+
## Epilog: Browser slikarstvo {/*epilogue-browser-paint*/}
198198

199-
After rendering is done and React updated the DOM, the browser will repaint the screen. Although this process is known as "browser rendering", we'll refer to it as "painting" to avoid confusion throughout the docs.
199+
Nakon što se renderovanje završi i React ažurira DOM, browser će ponovo oslikati ekran. Iako je ovaj proces poznat kao "browser renderovanje", mi ćemo ga osloviti sa "slikarstvo" da bi izbegli zabunu kroz dokumentaciju.
200200

201-
<Illustration alt="A browser painting 'still life with card element'." src="/images/docs/illustrations/i_browser-paint.png" />
201+
<Illustration alt="Browser slika 'mrtva priroda sa elementom kartice'." src="/images/docs/illustrations/i_browser-paint.png" />
202202

203203
<Recap>
204204

205-
* Any screen update in a React app happens in three steps:
206-
1. Trigger
205+
* Svako ažuriranje ekrana u React aplikaciji se dešava u tri faze:
206+
1. Pokretanje
207207
2. Render
208208
3. Commit
209-
* You can use Strict Mode to find mistakes in your components
210-
* React does not touch the DOM if the rendering result is the same as last time
209+
* Možete koristiti Strict Mode da pronađete greške u komponentama
210+
* React ne dira DOM ako je rezultat renderovanja isti kao prethodni put
211211

212212
</Recap>
213213

0 commit comments

Comments
 (0)