You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/content/learn/writing-markup-with-jsx.md
+69-69
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,24 @@
1
1
---
2
-
title: Writing Markup with JSX
2
+
title: Pisanje markup-a sa JSX-om
3
3
---
4
4
5
5
<Intro>
6
6
7
-
*JSX*is a syntax extension for JavaScript that lets you write HTML-like markup inside a JavaScript file. Although there are other ways to write components, most React developers prefer the conciseness of JSX, and most codebases use it.
7
+
*JSX*je sintaksna ekstenzija za JavaScript koja vam omogućava da pišete markup sličan HTML-u unutar JavaScript fajla. Iako postoje i drugi načini za pisanje komponenata, većina React developera preferira sažetost JSX-a, pa se zato koristi na većini projekata.
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearn>
12
12
13
-
*Why React mixes markup with rendering logic
14
-
*How JSX is different from HTML
15
-
*How to display information with JSX
13
+
*Zašto React kombinuje markup i logiku renderovanja
14
+
*Kako se JSX razlikuje od HTML-a
15
+
*Kako da prikažete informacije pomoću JSX-a
16
16
17
17
</YouWillLearn>
18
18
19
-
## JSX: Putting markup into JavaScript {/*jsx-putting-markup-into-javascript*/}
19
+
## JSX: Stavljanje markup-a unutar JavaScript-a {/*jsx-putting-markup-into-javascript*/}
20
20
21
-
The Web has been built on HTML, CSS, and JavaScript. For many years, web developers kept content in HTML, design in CSS, and logic in JavaScript—often in separate files! Content was marked up inside HTML while the page's logic lived separately in JavaScript:
21
+
Web je izgrađen pomoću HTML-a, CSS-a i JavaScript-a. Godinama su web developeri čuvali sadržaj u HTML-u, dizajn u CSS-u, a logiku u JavaScript-u, i to često u odvojenim fajlovima! Sadržaj se nalazio unutar HTML-a, dok je logika živela odvojeno u JavaScript-u:
22
22
23
23
<DiagramGroup>
24
24
@@ -36,53 +36,53 @@ JavaScript
36
36
37
37
</DiagramGroup>
38
38
39
-
But as the Web became more interactive, logic increasingly determined content. JavaScript was in charge of the HTML! This is why **in React, rendering logic and markup live together in the same place—components.**
39
+
Kako je web postajao interaktivniji, logika je značajno određivala sadržaj. JavaScript je bio zadužen za HTML! Zato, **u React-u, logika renderovanja i markup žive zajedno na jednom mestu—u komponentama**.
40
40
41
41
<DiagramGroup>
42
42
43
43
<Diagramname="writing_jsx_sidebar"height={330}width={325}alt="React component with HTML and JavaScript from previous examples mixed. Function name is Sidebar which calls the function isLoggedIn, highlighted in yellow. Nested inside the function highlighted in purple is the p tag from before, and a Form tag referencing the component shown in the next diagram.">
44
44
45
-
`Sidebar.js` React component
45
+
`Sidebar.js` React komponenta
46
46
47
47
</Diagram>
48
48
49
49
<Diagramname="writing_jsx_form"height={330}width={325}alt="React component with HTML and JavaScript from previous examples mixed. Function name is Form containing two handlers onClick and onSubmit highlighted in yellow. Following the handlers is HTML highlighted in purple. The HTML contains a form element with a nested input element, each with an onClick prop.">
50
50
51
-
`Form.js` React component
51
+
`Form.js` React komponenta
52
52
53
53
</Diagram>
54
54
55
55
</DiagramGroup>
56
56
57
-
Keeping a button's rendering logic and markup together ensures that they stay in sync with each other on every edit. Conversely, details that are unrelated, such as the button's markup and a sidebar's markup, are isolated from each other, making it safer to change either of them on their own.
57
+
Držanje logike renderovanja i markup-a za dugme na jednom mestu osigurava da će oni ostati sinhronizovani nakon svake promene. Nasuprot toga, detalji koji nisu povezani, kao što su markup-i za dugme i sidebar, izolovani su jedan od drugog, što omogućava lakšu promenu svakog od njih.
58
58
59
-
Each React component is a JavaScript function that may contain some markup that React renders into the browser. React components use a syntax extension called JSX to represent that markup. JSX looks a lot like HTML, but it is a bit stricter and can display dynamic information. The best way to understand this is to convert some HTML markup to JSX markup.
59
+
Svaka React komponenta je JavaScript funkcija koja može sadržati markup koji će React renderovati u pretraživaču. React komponente koriste sintaksnu ekstenziju pod imenom JSX da bi predstavile taj markup. JSX veoma liči na HTML, ali je malo strožiji i može prikazati dinamičke podatke. Najbolji način da ovo razumete je da konvertujete neki HTML markup u JSX markup.
60
60
61
61
<Note>
62
62
63
-
JSX and React are two separate things. They're often used together, but you *can*[use them independently](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#whats-a-jsx-transform) of each other. JSX is a syntax extension, while React is a JavaScript library.
63
+
JSX i React su dve odvojene stvari. Često se koriste zajedno, ali *možete*[ih koristiti odvojeno](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#whats-a-jsx-transform). JSX je sintaksna ekstenzija, dok je React JavaScript biblioteka.
64
64
65
65
</Note>
66
66
67
-
## Converting HTML to JSX {/*converting-html-to-jsx*/}
67
+
## Konvertovanje HTML-a u JSX {/*converting-html-to-jsx*/}
68
68
69
-
Suppose that you have some (perfectly valid) HTML:
69
+
Pretpostavimo da imate neki (potpuno validan) HTML:
70
70
71
71
```html
72
-
<h1>Hedy Lamarr's Todos</h1>
72
+
<h1>Hedy Lamarr-ina Todo lista</h1>
73
73
<img
74
74
src="https://i.imgur.com/yXOvdOSs.jpg"
75
75
alt="Hedy Lamarr"
76
76
class="photo"
77
77
>
78
78
<ul>
79
-
<li>Invent new traffic lights
80
-
<li>Rehearse a movie scene
81
-
<li>Improve the spectrum technology
79
+
<li>Izmisli nove semafore
80
+
<li>Vežbaj scenu iz filma
81
+
<li>Unapredi tehnologiju spektra
82
82
</ul>
83
83
```
84
84
85
-
And you want to put it into your component:
85
+
I želite da ga pomerite u vašu komponentu:
86
86
87
87
```js
88
88
exportdefaultfunctionTodoList() {
@@ -92,25 +92,25 @@ export default function TodoList() {
92
92
}
93
93
```
94
94
95
-
If you copy and paste it as is, it will not work:
95
+
Ako uradite samo copy/paste, to neće raditi:
96
96
97
97
98
98
<Sandpack>
99
99
100
100
```js
101
101
exportdefaultfunctionTodoList() {
102
102
return (
103
-
//This doesn't quite work!
104
-
<h1>Hedy Lamarr's Todos</h1>
103
+
//Ovo baš i ne radi!
104
+
<h1>Hedy Lamarr-ina Todo lista</h1>
105
105
<img
106
106
src="https://i.imgur.com/yXOvdOSs.jpg"
107
107
alt="Hedy Lamarr"
108
108
class="photo"
109
109
>
110
110
<ul>
111
-
<li>Invent new traffic lights
112
-
<li>Rehearse a movie scene
113
-
<li>Improve the spectrum technology
111
+
<li>Izmisli nove semafore
112
+
<li>Vežbaj scenu iz filma
113
+
<li>Unapredi tehnologiju spektra
114
114
</ul>
115
115
);
116
116
}
@@ -122,25 +122,25 @@ img { height: 90px }
122
122
123
123
</Sandpack>
124
124
125
-
This is because JSX is stricter and has a few more rules than HTML! If you read the error messages above, they'll guide you to fix the markup, or you can follow the guide below.
125
+
To je zato što je JSX strožiji i ima par pravila više od HTML-a! Ako pročitate poruke o greškama iznad, uputiće vas kako da popravite markup. Takođe, možete pratiti i uputstvo ispod.
126
126
127
127
<Note>
128
128
129
-
Most of the time, React's on-screen error messages will help you find where the problem is. Give them a read if you get stuck!
129
+
U većini slučajeva, React-ove poruke o greškama će vam pomoći da pronađete u čemu je problem. Pročitajte ih ako se zaglavite!
130
130
131
131
</Note>
132
132
133
-
## The Rules of JSX {/*the-rules-of-jsx*/}
133
+
## Pravila JSX-a {/*the-rules-of-jsx*/}
134
134
135
-
### 1. Return a single root element {/*1-return-a-single-root-element*/}
135
+
### 1. Vratite jedan root element {/*1-return-a-single-root-element*/}
136
136
137
-
To return multiple elements from a component, **wrap them with a single parent tag.**
137
+
Da biste vratili više elemenata iz komponente, **zamotajte ih u jedan roditeljski tag**.
138
138
139
-
For example, you can use a `<div>`:
139
+
Na primer, možete koristiti`<div>`:
140
140
141
141
```js {1,11}
142
142
<div>
143
-
<h1>Hedy Lamarr's Todos</h1>
143
+
<h1>Hedy Lamarr-ina Todo lista</h1>
144
144
<img
145
145
src="https://i.imgur.com/yXOvdOSs.jpg"
146
146
alt="Hedy Lamarr"
@@ -153,11 +153,11 @@ For example, you can use a `<div>`:
153
153
```
154
154
155
155
156
-
If you don't want to add an extra `<div>`to your markup, you can write `<>`and`</>` instead:
156
+
Ako ne želite da dodate novi `<div>`u vaš markup, možete umesto toga koristiti `<>`i`</>`:
157
157
158
158
```js {1,11}
159
159
<>
160
-
<h1>Hedy Lamarr's Todos</h1>
160
+
<h1>Hedy Lamarr-ina Todo lista</h1>
161
161
<img
162
162
src="https://i.imgur.com/yXOvdOSs.jpg"
163
163
alt="Hedy Lamarr"
@@ -169,21 +169,21 @@ If you don't want to add an extra `<div>` to your markup, you can write `<>` and
169
169
</>
170
170
```
171
171
172
-
This empty tag is called a *[Fragment.](/reference/react/Fragment)* Fragments let you group things without leaving any trace in the browser HTML tree.
172
+
Ovaj prazan tag se naziva *[Fragment](/reference/react/Fragment)*. Fragmenti vam omogućavaju da grupišete stvari bez uticaja na HTML stablo u pretraživaču.
173
173
174
174
<DeepDive>
175
175
176
-
#### Why do multiple JSX tags need to be wrapped? {/*why-do-multiple-jsx-tags-need-to-be-wrapped*/}
176
+
#### Zašto morate zamotati više JSX tag-ova? {/*why-do-multiple-jsx-tags-need-to-be-wrapped*/}
177
177
178
-
JSX looks like HTML, but under the hood it is transformed into plain JavaScript objects. You can't return two objects from a function without wrapping them into an array. This explains why you also can't return two JSX tags without wrapping them into another tag or a Fragment.
178
+
JSX liči na HTML, ali je ispod haube transformisan u obične JavaScript objekte. Ne možete vratiti dva objekta iz funkcije ako ih ne zamotate u niz. Ovo takođe objašnjava i zašto ne možete vratiti dva JSX tag-a bez da ih zamotate u drugi tag ili Fragment.
179
179
180
180
</DeepDive>
181
181
182
-
### 2. Close all the tags {/*2-close-all-the-tags*/}
182
+
### 2. Zatvorite sve tag-ove {/*2-close-all-the-tags*/}
183
183
184
-
JSX requires tags to be explicitly closed: self-closing tags like `<img>` must become `<img />`, and wrapping tags like `<li>oranges` must be written as `<li>oranges</li>`.
184
+
JSX zahteva da svi tag-ovi budu eksplicitno zatvoreni: samozatvarajući tag-ovi kao što je `<img>`moraju postati`<img />`, a obmotavajući tag-ovi poput`<li>pomorandže` moraju biti napisani kao`<li>pomorandže</li>`.
185
185
186
-
This is how Hedy Lamarr's image and list items look closed:
186
+
Ovako izgledaju Hedy Lamarr-ina slika i lista zatvoreni:
187
187
188
188
```js {2-6,8-10}
189
189
<>
@@ -193,18 +193,18 @@ This is how Hedy Lamarr's image and list items look closed:
193
193
class="photo"
194
194
/>
195
195
<ul>
196
-
<li>Invent new traffic lights</li>
197
-
<li>Rehearse a movie scene</li>
198
-
<li>Improve the spectrum technology</li>
196
+
<li>Izmisli nove semafore</li>
197
+
<li>Vežbaj scenu iz filma</li>
198
+
<li>Unapredi tehnologiju spektra</li>
199
199
</ul>
200
200
</>
201
201
```
202
202
203
-
### 3. camelCase <s>all</s> most of the things! {/*3-camelcase-salls-most-of-the-things*/}
203
+
### 3. Koristite camelCase za <s>sve</s> većinu stvari! {/*3-camelcase-salls-most-of-the-things*/}
204
204
205
-
JSX turns into JavaScript and attributes written in JSX become keys of JavaScript objects. In your own components, you will often want to read those attributes into variables. But JavaScript has limitations on variable names. For example, their names can't contain dashes or be reserved words like `class`.
205
+
JSX se pretvara u JavaScript i atributi napisani u JSX-u postaju ključevi za JavaScript objekte. U vašim komponentama, često ćete želeti da pročitate te atribute u promenljive. Ali JavaScript ima ograničenja za imena promenljivih. Na primer, imena ne mogu sadržati crtice ili rezervisane reči kao što je`class`.
206
206
207
-
This is why, in React, many HTML and SVG attributes are written in camelCase. For example, instead of `stroke-width` you use `strokeWidth`. Since `class` is a reserved word, in React you write `className` instead, named after the [corresponding DOM property](https://developer.mozilla.org/en-US/docs/Web/API/Element/className):
207
+
Zato se, u React-u, većina HTML i SVG atributa pišu u camelCase-u. Na primer, umesto `stroke-width`koristićete `strokeWidth`. Pošto je `class`rezervisana reč, u React-u ćete pisati`className`, koji je nastao na osnovu [odgovarajućeg polja u DOM-u](https://developer.mozilla.org/en-US/docs/Web/API/Element/className):
208
208
209
209
```js {4}
210
210
<img
@@ -214,36 +214,36 @@ This is why, in React, many HTML and SVG attributes are written in camelCase. Fo
214
214
/>
215
215
```
216
216
217
-
Youcan [findalltheseattributesinthelistofDOMcomponentprops.](/reference/react-dom/components/common)Ifyougetonewrong, don't worry—React will print a message with a possible correction to the [browser console.](https://developer.mozilla.org/docs/Tools/Browser_Console)
217
+
Možete [pronaći sve te atribute u listi props-a DOM komponente](/reference/react-dom/components/common). Ako neki i pogrešite, ne brinite—React će napisati poruku sa mogućom ispravkom u [konzoli pretraživača](https://developer.mozilla.org/docs/Tools/Browser_Console).
218
218
219
219
<Pitfall>
220
220
221
-
For historical reasons, [`aria-*`](https://developer.mozilla.org/docs/Web/Accessibility/ARIA) and [`data-*`](https://developer.mozilla.org/docs/Learn/HTML/Howto/Use_data_attributes) attributes are written as in HTML with dashes.
221
+
Iz istorijskih razloga, [`aria-*`](https://developer.mozilla.org/docs/Web/Accessibility/ARIA)i[`data-*`](https://developer.mozilla.org/docs/Learn/HTML/Howto/Use_data_attributes)atributi se pišu sa crticama kao i u HTML-u.
222
222
223
223
</Pitfall>
224
224
225
-
### Pro-tip: Use a JSX Converter {/*pro-tip-use-a-jsx-converter*/}
Converting all these attributes in existing markup can be tedious! We recommend using a [converter](https://transform.tools/html-to-jsx) to translate your existing HTML and SVG to JSX. Converters are very useful in practice, but it'sstillworthunderstandingwhatisgoingonsothatyoucancomfortablywriteJSXonyourown.
227
+
Konvertovanje svih tih atributa u postojeći markup može biti naporno! Preporučujemo vam da koristite [konverter](https://transform.tools/html-to-jsx)za pretvaranje postojećeg HTML-a i SVG-a u JSX. Konverteri su veoma zgodni u praksi, ali je i dalje važno da razumete šta se događa kako biste lagodno mogli da pišete JSX.
228
228
229
-
Hereisyourfinalresult:
229
+
Ovo je konačni rezultat:
230
230
231
231
<Sandpack>
232
232
233
233
```js
234
234
exportdefaultfunctionTodoList() {
235
235
return (
236
236
<>
237
-
<h1>Hedy Lamarr's Todos</h1>
237
+
<h1>Hedy Lamarr-ina Todo lista</h1>
238
238
<img
239
239
src="https://i.imgur.com/yXOvdOSs.jpg"
240
240
alt="Hedy Lamarr"
241
241
className="photo"
242
242
/>
243
243
<ul>
244
-
<li>Invent new traffic lights</li>
245
-
<li>Rehearse a movie scene</li>
246
-
<li>Improve the spectrum technology</li>
244
+
<li>Izmisli nove semafore</li>
245
+
<li>Vežbaj scenu iz filma</li>
246
+
<li>Unapredi tehnologiju spektra</li>
247
247
</ul>
248
248
</>
249
249
);
@@ -258,34 +258,34 @@ img { height: 90px }
258
258
259
259
<Recap>
260
260
261
-
NowyouknowwhyJSXexistsandhowtouseitincomponents:
261
+
Sada znate zašto JSX postoji i kako da ga koristite u komponentama:
0 commit comments