`'s `color` to red without impacting `background-color`. Similarly, **different React contexts don't override each other.** Each context that you make with `createContext()` is completely separate from other ones, and ties together components using and providing *that particular* context. One component may use or provide many different contexts without a problem.
+U CSS-u, različita polja poput `color` i `background-color` ne override-uju jedno drugo. Možete postaviti `color` svih `
`-ova na crveno bez da utičete na `background-color`. Slično tome, **različiti React context-i ne override-uju jedan drugog**. Svaki context koji napravite sa `createContext()` je potpuno odvojen od ostalih i povezuje komponente koje koriste i pružaju *taj specifični* context. Jedna komponenta, bez problema, može koristiti ili pružati neograničen broj context-a.
-## Before you use context {/*before-you-use-context*/}
+## Pre nego što upotrebite context {/*before-you-use-context*/}
-Context is very tempting to use! However, this also means it's too easy to overuse it. **Just because you need to pass some props several levels deep doesn't mean you should put that information into context.**
+Context je veoma primamljiv za upotrebu! Međutim, ovo takođe znači da je lako preterati sa njegovom upotrebom. **To što je potrebno proslediti neke props-e par nivoa u dubinu ne znači da biste trebali tu informaciju staviti u context.**
-Here's a few alternatives you should consider before using context:
+Evo par alternativa koje biste trebali razmotriti pre upotrebe context-a:
-1. **Start by [passing props.](/learn/passing-props-to-a-component)** If your components are not trivial, it's not unusual to pass a dozen props down through a dozen components. It may feel like a slog, but it makes it very clear which components use which data! The person maintaining your code will be glad you've made the data flow explicit with props.
-2. **Extract components and [pass JSX as `children`](/learn/passing-props-to-a-component#passing-jsx-as-children) to them.** If you pass some data through many layers of intermediate components that don't use that data (and only pass it further down), this often means that you forgot to extract some components along the way. For example, maybe you pass data props like `posts` to visual components that don't use them directly, like `
`. Instead, make `Layout` take `children` as a prop, and render `
`. This reduces the number of layers between the component specifying the data and the one that needs it.
+1. **Počnite sa [prosleđivanjem props-a](/learn/passing-props-to-a-component).** Ako vaše komponente nisu trivijalne, nije neuobičajeno da prosleđujete nekolicinu props-a kroz nekolicinu komponenata. Možda deluje naporno, ali jasno govori koje komponente koriste koje podatke! Osoba koja bude održavala vaš kod će biti srećna da ste eksplicitno označili tok podataka kroz props.
+2. **Izdvojite komponente i [prosledite im JSX kao `children`](/learn/passing-props-to-a-component#passing-jsx-as-children).** Ako prosleđujete podatke kroz mnogo slojeva središnjih komponenata koje ne koriste te podatke (i samo ih prosleđuju na dole), to obično znači da ste zaboravili da izdvojite neke komponente. Na primer, možda prosleđujete props-e poput `posts` u vizuelne komponente koje ih ne koriste direktno, npr. `
`. Umesto toga, napravite da `Layout` prima `children` kao prop i renderujte `
`. Ovo smanjuje broj slojeva između komponente koja specificira podatke i one kojoj su podaci potrebni.
-If neither of these approaches works well for you, consider context.
+Ako nijedan od ovih pristupa ne radi dobro, razmotrite context.
-## Use cases for context {/*use-cases-for-context*/}
+## Slučajevi korišćenja context-a {/*use-cases-for-context*/}
-* **Theming:** If your app lets the user change its appearance (e.g. dark mode), you can put a context provider at the top of your app, and use that context in components that need to adjust their visual look.
-* **Current account:** Many components might need to know the currently logged in user. Putting it in context makes it convenient to read it anywhere in the tree. Some apps also let you operate multiple accounts at the same time (e.g. to leave a comment as a different user). In those cases, it can be convenient to wrap a part of the UI into a nested provider with a different current account value.
-* **Routing:** Most routing solutions use context internally to hold the current route. This is how every link "knows" whether it's active or not. If you build your own router, you might want to do it too.
-* **Managing state:** As your app grows, you might end up with a lot of state closer to the top of your app. Many distant components below may want to change it. It is common to [use a reducer together with context](/learn/scaling-up-with-reducer-and-context) to manage complex state and pass it down to distant components without too much hassle.
+* **Theming:** Ako vaša aplikacija dozvoljava korisniku da menja izgled (npr. tamni režim), možete postaviti context provider na vrh aplikacije i koristiti taj context u komponentama koje trebaju menjati svoj izgled.
+* **Trenutni nalog:** Mnogim komponentama može biti potreban trenutno ulogovani korisnik. Upotreba context-a čini čitanje podataka zgodnijim bilo gde u stablu. Neke aplikacije omogućavaju istovremeno korišćenje više naloga (npr. ostavljanje komentara u ime drugog korisnika). U tim slučajevima može biti zgodno da obmotate deo UI-a u ugnježdeni provider sa drugačijom vrednošću za trenutni nalog.
+* **Rutiranje:** Većina rešenja za rutiranje interno koristi context da čuva trenutnu rutu. Zbog toga svaki link "zna" da li je aktivan ili ne. Ako pravite sopstveni ruter, verovatno ćete i vi želeti ovo da koristite.
+* **Upravljanje state-om:** Kako vam aplikacija raste, možete završiti sa mnogo state-ova koji su blizu vrha aplikacije. Mnoge komponente ispod mogu želeti da ih promene. Za upravljanje kompleksnim state-ovima uobičajeno je da se [koristi reducer zajedno sa context-om](/learn/scaling-up-with-reducer-and-context), kako bi se podaci prosledili udaljenim komponentama bez mnogo muke.
-Context is not limited to static values. If you pass a different value on the next render, React will update all the components reading it below! This is why context is often used in combination with state.
+Context nije ograničen na statičke vrednosti. Ako prosledite drugačiju vrednost u narednom renderu, React će ažurirati sve komponente ispod koje ga čitaju! Zbog toga se context često koristi u kombinaciji sa state-om.
-In general, if some information is needed by distant components in different parts of the tree, it's a good indication that context will help you.
+U suštini, ako je neka informacija potrebna udaljenim komponentama u različitim delovima stabla, dobar je znak da vam context može pomoći.
-* Context lets a component provide some information to the entire tree below it.
-* To pass context:
- 1. Create and export it with `export const MyContext = createContext(defaultValue)`.
- 2. Pass it to the `useContext(MyContext)` Hook to read it in any child component, no matter how deep.
- 3. Wrap children into `` to provide it from a parent.
-* Context passes through any components in the middle.
-* Context lets you write components that "adapt to their surroundings".
-* Before you use context, try passing props or passing JSX as `children`.
+* Context omogućava komponenti da pruži neku informaciju u celo stablo ispod.
+* Da biste prosledili context:
+ 1. Napravite i export-ujte ga sa `export const MyContext = createContext(defaultValue)`.
+ 2. Prosledite ga u `useContext(MyContext)` Hook kako biste mogli da ga čitate u bilo kojoj dečjoj komponenti, bez obzira koliko duboko bila.
+ 3. Da biste context pružili iz roditelja, obmotajte decu sa ``.
+* Context prolazi kroz bilo koju središnju komponentu.
+* Context vam omogućava da pišete komponente koje se "prilagođavaju svom okruženju".
+* Pre nego što upotrebite context, probajte da prosledite props ili da prosledite JSX kao `children`.
-#### Replace prop drilling with context {/*replace-prop-drilling-with-context*/}
+#### Zameniti prop drilling sa context-om {/*replace-prop-drilling-with-context*/}
-In this example, toggling the checkbox changes the `imageSize` prop passed to each ``. The checkbox state is held in the top-level `App` component, but each `` needs to be aware of it.
+U ovom primeru, klik na checkbox menja `imageSize` prop prosleđen u svaki ``. Checkbox state se čuva na vrhu, u `App` komponenti, ali svaki `` mora da zna za njega.
-Currently, `App` passes `imageSize` to `List`, which passes it to each `Place`, which passes it to the `PlaceImage`. Remove the `imageSize` prop, and instead pass it from the `App` component directly to `PlaceImage`.
+Trenutno, `App` prosleđuje `imageSize` u `List`, koji ga prosleđuje u svaki `Place`, koji ga prosleđuje u `PlaceImage`. Uklonite `imageSize` prop i umesto toga informaciju prosledite direktno iz `App` komponente u `PlaceImage`.
-You can declare context in `Context.js`.
+Možete deklarisati context u `Context.js`.
@@ -905,7 +905,7 @@ export default function App() {
setIsLarge(e.target.checked);
}}
/>
- Use large images
+ Koristi veće slike
@@ -959,38 +959,38 @@ function PlaceImage({ place, imageSize }) {
```js src/data.js
export const places = [{
id: 0,
- name: 'Bo-Kaap in Cape Town, South Africa',
- description: 'The tradition of choosing bright colors for houses began in the late 20th century.',
+ name: 'Bo-Kaap u Kejptaunu, Južna Afrika',
+ description: 'Tradicija odabira svetlih boja za kuće je započeta krajem 20. veka.',
imageId: 'K9HVAGH'
}, {
- id: 1,
- name: 'Rainbow Village in Taichung, Taiwan',
- description: 'To save the houses from demolition, Huang Yung-Fu, a local resident, painted all 1,200 of them in 1924.',
+ id: 1,
+ name: 'Selo duge u Taichung-u, Tajvan',
+ description: 'Kako bi spasio kuće od rušenja, lokalni stanovnik Huang Yung-Fu, 1924. godine je ofarbao svih 1,200 kuća.',
imageId: '9EAYZrt'
}, {
- id: 2,
- name: 'Macromural de Pachuca, Mexico',
- description: 'One of the largest murals in the world covering homes in a hillside neighborhood.',
+ id: 2,
+ name: 'Macromural de Pachuca, Meksiko',
+ description: 'Jedan od najvećih murala na svetu koji pokriva brdsko naselje.',
imageId: 'DgXHVwu'
}, {
- id: 3,
- name: 'Selarón Staircase in Rio de Janeiro, Brazil',
- description: 'This landmark was created by Jorge Selarón, a Chilean-born artist, as a "tribute to the Brazilian people."',
+ id: 3,
+ name: 'Stepenište Selarón u Rio de Žaneiru, Brazil',
+ description: 'Ovu znamenitost je napravio Jorge Selarón, čileanski umetnik, kao "počast brazilskom narodu".',
imageId: 'aeO3rpI'
}, {
- id: 4,
- name: 'Burano, Italy',
- description: 'The houses are painted following a specific color system dating back to 16th century.',
+ id: 4,
+ name: 'Burano, Italija',
+ description: 'Kuće su ofarbane specifičnim sistemom boja koji datira iz 16. veka.',
imageId: 'kxsph5C'
}, {
- id: 5,
- name: 'Chefchaouen, Marocco',
- description: 'There are a few theories on why the houses are painted blue, including that the color repels mosquitos or that it symbolizes sky and heaven.',
+ id: 5,
+ name: 'Chefchaouen, Maroko',
+ description: 'Postoji par teorija zašto su kuće ofarbane u plavo, od toga da ta boja odbija komarce do toga da označava nebo i raj.',
imageId: 'rTqKo46'
}, {
id: 6,
- name: 'Gamcheon Culture Village in Busan, South Korea',
- description: 'In 2009, the village was converted into a cultural hub by painting the houses and featuring exhibitions and art installations.',
+ name: 'Selo kulture Gamcheon u Busanu, Južna Koreja',
+ description: 'Selo je 2009. godine pretvoreno u kulturni centar farbanjem kuća i postavljanjem izložbi i umetničkih instalacija.',
imageId: 'ZfQOOzf'
}];
```
@@ -1020,9 +1020,9 @@ li {
-Remove `imageSize` prop from all the components.
+Uklonite `imageSize` prop iz svih komponenata.
-Create and export `ImageSizeContext` from `Context.js`. Then wrap the List into `` to pass the value down, and `useContext(ImageSizeContext)` to read it in the `PlaceImage`:
+Napravite i export-ujte `ImageSizeContext` iz `Context.js`. Onda, obmotajte List sa `` kako biste vrednost prosledili na dole, a onda iskoristite `useContext(ImageSizeContext)` da ga pročitate u `PlaceImage`:
@@ -1047,7 +1047,7 @@ export default function App() {
setIsLarge(e.target.checked);
}}
/>
- Use large images
+ Koristi veće slike
@@ -1098,38 +1098,38 @@ export const ImageSizeContext = createContext(500);
```js src/data.js
export const places = [{
id: 0,
- name: 'Bo-Kaap in Cape Town, South Africa',
- description: 'The tradition of choosing bright colors for houses began in the late 20th century.',
+ name: 'Bo-Kaap u Kejptaunu, Južna Afrika',
+ description: 'Tradicija odabira svetlih boja za kuće je započeta krajem 20. veka.',
imageId: 'K9HVAGH'
}, {
- id: 1,
- name: 'Rainbow Village in Taichung, Taiwan',
- description: 'To save the houses from demolition, Huang Yung-Fu, a local resident, painted all 1,200 of them in 1924.',
+ id: 1,
+ name: 'Selo duge u Taichung-u, Tajvan',
+ description: 'Kako bi spasio kuće od rušenja, lokalni stanovnik Huang Yung-Fu, 1924. godine je ofarbao svih 1,200 kuća.',
imageId: '9EAYZrt'
}, {
- id: 2,
- name: 'Macromural de Pachuca, Mexico',
- description: 'One of the largest murals in the world covering homes in a hillside neighborhood.',
+ id: 2,
+ name: 'Macromural de Pachuca, Meksiko',
+ description: 'Jedan od najvećih murala na svetu koji pokriva brdsko naselje.',
imageId: 'DgXHVwu'
}, {
- id: 3,
- name: 'Selarón Staircase in Rio de Janeiro, Brazil',
+ id: 3,
+ name: 'Stepenište Selarón u Rio de Žaneiru, Brazil',
description: 'This landmark was created by Jorge Selarón, a Chilean-born artist, as a "tribute to the Brazilian people".',
imageId: 'aeO3rpI'
}, {
- id: 4,
- name: 'Burano, Italy',
- description: 'The houses are painted following a specific color system dating back to 16th century.',
+ id: 4,
+ name: 'Burano, Italija',
+ description: 'Kuće su ofarbane specifičnim sistemom boja koji datira iz 16. veka.',
imageId: 'kxsph5C'
}, {
- id: 5,
- name: 'Chefchaouen, Marocco',
- description: 'There are a few theories on why the houses are painted blue, including that the color repels mosquitos or that it symbolizes sky and heaven.',
+ id: 5,
+ name: 'Chefchaouen, Maroko',
+ description: 'Postoji par teorija zašto su kuće ofarbane u plavo, od toga da ta boja odbija komarce do toga da označava nebo i raj.',
imageId: 'rTqKo46'
}, {
id: 6,
- name: 'Gamcheon Culture Village in Busan, South Korea',
- description: 'In 2009, the village was converted into a cultural hub by painting the houses and featuring exhibitions and art installations.',
+ name: 'Selo kulture Gamcheon u Busanu, Južna Koreja',
+ description: 'Selo je 2009. godine pretvoreno u kulturni centar farbanjem kuća i postavljanjem izložbi i umetničkih instalacija.',
imageId: 'ZfQOOzf'
}];
```
@@ -1157,7 +1157,7 @@ li {
-Note how components in the middle don't need to pass `imageSize` anymore.
+Primetite da središnje komponente više ne moraju da prosleđuju `imageSize`.