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/importing-and-exporting-components.md
+70-72
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,26 @@
1
1
---
2
-
title: Importing and Exporting Components
2
+
title: Import-ovanje i export-ovanje komponenata
3
3
---
4
4
5
5
<Intro>
6
6
7
-
The magic of components lies in their reusability: you can create components that are composed of other components. But as you nest more and more components, it often makes sense to start splitting them into different files. This lets you keep your files easy to scan and reuse components in more places.
7
+
Magija komponenata leži u njihovoj upotrebljivosti: možete kreirati komponente koje se sastoje iz drugih komponenata. Međutim, ugnježdavanjem novih i novih komponenata, često ima smisla započeti njihovu podelu u različite fajlove. Ovo vam omogućava da fajlove lakše skenirate i koristite komponente na više mesta.
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearn>
12
12
13
-
*What a root component file is
14
-
*How to import and export a component
15
-
*When to use default and named imports and exports
16
-
*How to import and export multiple components from one file
17
-
*How to split components into multiple files
13
+
*Šta je to fajl root komponente
14
+
*Kako da import-ujete i export-ujete komponentu
15
+
*Kada da koristite default i imenovane import-e i export-e
16
+
*Kako da import-ujete i export-ujete više komponenata iz jednog fajla
17
+
*Kako da podelite komponente u više fajlova
18
18
19
19
</YouWillLearn>
20
20
21
-
## The root component file {/*the-root-component-file*/}
These currently live in a **root component file,** named `App.js` in this example. Depending on your setup, your root component could be in another file, though. If you use a framework with file-based routing, such as Next.js, your root component will be different for every page.
55
+
One trenutno žive u **fajlu root komponente**, koji se u ovom primeru zove `App.js`. U zavisnosti od vaših podešavanja, root komponenta može biti i u drugom fajlu. Ako koristite neki framework sa fajl rutiranjem, kao što je Next.js, vaša root komponenta će biti drugačija na svakoj stranici.
56
56
57
-
## Exporting and importing a component {/*exporting-and-importing-a-component*/}
57
+
## Export-ovanje i import-ovanje komponente {/*exporting-and-importing-a-component*/}
58
58
59
-
What if you want to change the landing screen in the future and put a list of science books there? Or place all the profiles somewhere else? It makes sense to move `Gallery`and`Profile`out of the root component file. This will make them more modular and reusable in other files. You can move a component in three steps:
59
+
Šta ako želite da promenite landing stranicu i prikažete listu naučnih knjiga na njoj? Ili da postavite sve profile na neko drugo mesto? Ima smisla pomeriti `Gallery`i`Profile`izvan fajla root komponente. To će im omogućiti da budu modularnije i reusable. Komponentu možete pomeriti u tri koraka:
60
60
61
-
1.**Make**a new JS file to put the components in.
62
-
2.**Export**your function component from that file (using either[default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_the_default_export)or [named](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_named_exports)exports).
63
-
3.**Import**it in the file where you’ll use the component (using the corresponding technique for importing [default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#importing_defaults)or [named](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#import_a_single_export_from_a_module)exports).
61
+
1.**Napravite**novi JS fajl gde ćete smestiti komponente.
62
+
2.**Export-ujte**vašu funkciju komponente iz tog fajla (koristeći ili[default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_the_default_export)ili [imenovane](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_named_exports)export-e).
63
+
3.**Import-ujte**ih u fajl gde ćete ih koristiti (pomoću odgovarajuće tehnike import-ovanja [default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#importing_defaults)ili [imenovanih](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#import_a_single_export_from_a_module)export-a).
64
64
65
-
Here both `Profile`and`Gallery`have been moved out of `App.js`into a new file called `Gallery.js`. Now you can change `App.js`to import `Gallery`from`Gallery.js`:
65
+
Sada su i `Profile`i`Gallery`pomereni iz `App.js`u fajl pod imenom `Gallery.js`. Sada možete promeniti `App.js`da import-uje`Gallery`iz`Gallery.js`:
-Export-uje root `App`komponentu kao **default export**.
115
115
116
116
117
117
<Note>
118
118
119
-
You may encounter files that leave off the`.js`file extension like so:
119
+
Možete se susresti sa fajlovima koji ne koriste`.js`ekstenziju:
120
120
121
121
```js
122
122
importGalleryfrom'./Gallery';
123
123
```
124
124
125
-
Either`'./Gallery.js'`or`'./Gallery'`will work with React, though the former is closer to how[native ES Modules](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules)work.
125
+
I`'./Gallery.js'`i`'./Gallery'`će raditi u React-u, ali je prvi način bliži tome kako[native ES moduli](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules)rade.
126
126
127
127
</Note>
128
128
129
129
<DeepDive>
130
130
131
-
#### Default vs named exports {/*default-vs-named-exports*/}
131
+
#### Default vs imenovani export-i {/*default-vs-named-exports*/}
132
132
133
-
There are two primary ways to export values with JavaScript: default exports and named exports. So far, our examples have only used default exports. But you can use one or both of them in the same file. **A file can have no more than one _default_ export, but it can have as many _named_ exports as you like.**
133
+
Postoje dva primarna načina za export-ovanje vrednosti u JavaScript-u: default export-i i imenovani export-i. Naši primeri su do sad koristili samo default export-e. Možete koristiti jedan ili oba načina u istom fajlu. **Fajl ne sme imati više od jednog _default_ export-a, ali može imati koliko god želite _imenovanih_ export-a.**
134
134
135
-

135
+

136
136
137
-
How you export your component dictates how you must import it. You will get an error if you try to import a default export the same way you would a named export! This chart can help you keep track:
137
+
Način na koji export-ujete komponentu diktira način za njeno import-ovanje. Dobićete grešku ako pokušate da import-ujete default export na isti način kao i imenovani export! Ova tabela vam može pomoći da bolje razumete:
138
138
139
-
|Syntax| Export statement| Import statement|
140
-
| ----------- | ----------- | -----------|
141
-
| Default |`export default function Button() {}`|`import Button from './Button.js';`|
142
-
|Named |`export function Button() {}`|`import { Button } from './Button.js';`|
139
+
|Sintaksa| Export iskaz| Import iskaz |
140
+
| ----------- | ----------- | ----------- |
141
+
| Default |`export default function Button() {}`|`import Button from './Button.js';`|
142
+
|Imenovano|`export function Button() {}`|`import { Button } from './Button.js';`|
143
143
144
-
When you write a _default_ import, you can put any name you want after `import`. For example, you could write `import Banana from './Button.js'` instead and it would still provide you with the same default export. In contrast, with named imports, the name has to match on both sides. That's why they are called _named_ imports!
144
+
Kada koristite _default_ import, možete staviti bilo koje ime nakon `import`-a. Na primer, možete napisati `import Banana from './Button.js'`, ali ćete i dalje dobiti isti default export. Nasuprot tome, sa imenovanim import-ima, ime mora da se poklapa na obe strane. Zato se i nazivaju _imenovani_ import-i!
145
145
146
-
**People often use default exports if the file exports only one component, and use named exports if it exports multiple components and values.**Regardless of which coding style you prefer, always give meaningful names to your component functions and the files that contain them. Components without names, like`export default () => {}`, are discouraged because they make debugging harder.
146
+
**Ljudi često koriste default export-e ako fajl export-uje samo jednu komponentu, a imenovane export-e ako fajl export-uje više komponenata i vrednosti.**Koji god stil kodiranja da preferirate, uvek dajte smislena imena funkcijama komponenata i fajlovima u kojima se nalaze. Komponente bez imena poput`export default () => {}` ne bi trebale da se koriste jer otežavaju debug-ovanje.
147
147
148
148
</DeepDive>
149
149
150
-
## Exporting and importing multiple components from the same file {/*exporting-and-importing-multiple-components-from-the-same-file*/}
150
+
## Export-ovanje i import-ovanje više komponenata iz istog fajla {/*exporting-and-importing-multiple-components-from-the-same-file*/}
151
151
152
-
What if you want to show just one `Profile`instead of a gallery? You can export the `Profile`component, too. But`Gallery.js`already has a *default* export, and you can't have _two_ default exports. You could create a new file with a default export, or you could add a *named* export for`Profile`. **A file can only have one default export, but it can have numerous named exports!**
152
+
Šta ako želite prikazati samo jedan `Profile`umesto galerije? Možete export-ovati `Profile`komponentu takođe. Ali`Gallery.js`već ima *default* export, a ne možete imati _dva_ default export-a. Možete kreirati novi fajl sa default export-om, ili možete dodati *imenovani* export za`Profile`. **Fajl može imati samo jedan default export, ali može imati bezbroj imenovanih export-a!**
153
153
154
154
<Note>
155
155
156
-
To reduce the potential confusion between default and named exports, some teams choose to only stick to one style (default or named), or avoid mixing them in a single file. Do what works best for you!
156
+
Da bi izbegli zabunu između default i imenovanih export-a, neki timovi odluče da se drže jednog načina (default ili imenovani), ili izbegavaju upotrebu oba u istom fajlu. Koristite ono što vam najviše odgovara!
157
157
158
158
</Note>
159
159
160
-
First, **export**`Profile`from`Gallery.js`using a named export (no `default` keyword):
160
+
Prvo, **export-ujte**`Profile`iz`Gallery.js`upotrebom imenovanog export-a (bez ključne reči `default`):
161
161
162
162
```js
163
163
exportfunctionProfile() {
164
164
// ...
165
165
}
166
166
```
167
167
168
-
Then, **import**`Profile`from`Gallery.js`to`App.js`using a named import (with the curly braces):
168
+
Nakon toga, **import-ujte**`Profile`iz`Gallery.js`u`App.js`upotrebom imenovanog import-a (sa vitičastim zagradama):
169
169
170
170
```js
171
171
import { Profile } from'./Gallery.js';
172
172
```
173
173
174
-
Finally, **render**`<Profile />`from the `App`component:
174
+
Na kraju, **renderujte**`<Profile />`u `App`komponenti:
175
175
176
176
```js
177
177
exportdefaultfunctionApp() {
178
178
return<Profile />;
179
179
}
180
180
```
181
181
182
-
Now`Gallery.js`contains two exports: a default `Gallery` export, and a named `Profile` export. `App.js`imports both of them. Try editing `<Profile />`to`<Gallery />`and back in this example:
182
+
Sada`Gallery.js`sadrži dva export-a: default `Gallery` export i imenovani `Profile` export. `App.js`ih oba import-uje. Probajte da menjate `<Profile />`i`<Gallery />`naizmenično:
-Export-uje root `App`komponentu kao **default export**.
234
234
235
235
<Recap>
236
236
237
-
On this page you learned:
237
+
Na ovoj stranici ste naučili:
238
238
239
-
*What a root component file is
240
-
*How to import and export a component
241
-
*When and how to use default and named imports and exports
242
-
*How to export multiple components from the same file
239
+
*Šta je to fajl root komponente
240
+
*Kako da import-ujete i export-ujete komponentu
241
+
*Kada i kako da koristite default i imenovane import-e i export-e
242
+
*Kako da export-ujete više komponenata iz istog fajla
243
243
244
244
</Recap>
245
245
246
-
247
-
248
246
<Challenges>
249
247
250
-
#### Split the components further {/*split-the-components-further*/}
248
+
#### Delite komponente dalje {/*split-the-components-further*/}
251
249
252
-
Currently, `Gallery.js`exports both`Profile`and`Gallery`, which is a bit confusing.
250
+
Trenutno, `Gallery.js`export-uje i`Profile`i`Gallery`, što je malo zbunjujuće.
253
251
254
-
Move the `Profile`component to its own`Profile.js`, and then change the`App`component to render both`<Profile />`and`<Gallery />`one after another.
252
+
Pomerite `Profile`komponentu u zaseban fajl`Profile.js`, a nakon toga izmenite`App`komponentu da renderuje i`<Profile />`i`<Gallery />`komponente jednu za drugom.
255
253
256
-
You may use either a default or a named export for`Profile`, but make sure that you use the corresponding import syntax in both`App.js`and `Gallery.js`! You can refer to the table from the deep dive above:
254
+
Možete koristiti i default i imenovani export za`Profile`, ali se potrudite da iskoristite odgovarajuću import sintaksu i u`App.js`i u `Gallery.js`! Možete se osloniti na već spomenutu tabelu:
257
255
258
-
|Syntax| Export statement| Import statement|
259
-
| ----------- | ----------- | -----------|
260
-
| Default |`export default function Button() {}`|`import Button from './Button.js';`|
261
-
|Named |`export function Button() {}`|`import { Button } from './Button.js';`|
256
+
|Sintaksa| Export iskaz| Import iskaz |
257
+
| ----------- | ----------- | ----------- |
258
+
| Default |`export default function Button() {}`|`import Button from './Button.js';`|
259
+
|Imenovano|`export function Button() {}`|`import { Button } from './Button.js';`|
262
260
263
261
<Hint>
264
262
265
-
Don't forget to import your components where they are called. Doesn't`Gallery`use`Profile`, too?
263
+
Ne zaboravite da import-ujete komponente na mestu gde ih koristite. I`Gallery`koristi`Profile`, zar ne?
266
264
267
265
</Hint>
268
266
@@ -282,7 +280,7 @@ export default function App() {
0 commit comments