From 71a8d0f87a91de10531091559f3966accf2f6c72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rado=C5=A1=20Mili=C4=87ev?=
<40705899+rammba@users.noreply.github.com>
Date: Tue, 13 May 2025 17:11:16 +0200
Subject: [PATCH] Translate sharing-state-between-components.md
---
.../learn/sharing-state-between-components.md | 208 +++++++++---------
1 file changed, 104 insertions(+), 104 deletions(-)
diff --git a/src/content/learn/sharing-state-between-components.md b/src/content/learn/sharing-state-between-components.md
index 52eaf28f..b59ade26 100644
--- a/src/content/learn/sharing-state-between-components.md
+++ b/src/content/learn/sharing-state-between-components.md
@@ -1,31 +1,31 @@
---
-title: Sharing State Between Components
+title: Deljenje state-a između komponenata
---
-Sometimes, you want the state of two components to always change together. To do it, remove state from both of them, move it to their closest common parent, and then pass it down to them via props. This is known as *lifting state up,* and it's one of the most common things you will do writing React code.
+Ponekad želite da se state-ovi dve komponente menjaju zajedno. Da biste to uradili, uklonite state iz obe komponente, pomerite ga u najbližeg zajedničkog roditelja i prosledite ga nazad kroz props. Ovo je poznato kao *podizanje state-a* i jedna je od najčešćih stvari koje ćete pisati u React kodu.
-- How to share state between components by lifting it up
-- What are controlled and uncontrolled components
+- Kako da podizanjem delite state između komponenata
+- Šta su kontrolisane i nekontrolisane komponente
-## Lifting state up by example {/*lifting-state-up-by-example*/}
+## Podizanje state-a uz primer {/*lifting-state-up-by-example*/}
-In this example, a parent `Accordion` component renders two separate `Panel`s:
+U ovom primeru, roditeljska `Accordion` komponenta renderuje dva različita `Panel`-a:
* `Accordion`
- `Panel`
- `Panel`
-Each `Panel` component has a boolean `isActive` state that determines whether its content is visible.
+Svaka `Panel` komponenta ima boolean `isActive` state koji određuje da li je sadržaj vidljiv.
-Press the Show button for both panels:
+Pritisnite dugme "Prikaži" na oba panel-a:
@@ -41,7 +41,7 @@ function Panel({ title, children }) {
{children}
) : (
)}
@@ -51,12 +51,12 @@ function Panel({ title, children }) {
export default function Accordion() {
return (
<>
-
Almaty, Kazakhstan
-
- With a population of about 2 million, Almaty is Kazakhstan's largest city. From 1929 to 1997, it was its capital city.
+
Almati, Kazahstan
+
+ Sa populacijom od oko 2 miliona, Almati je najveći grad u Kazahstanu. Bio je glavni grad od 1929. do. 1997. godine.
-
- The name comes from алма, the Kazakh word for "apple" and is often translated as "full of apples". In fact, the region surrounding Almaty is thought to be the ancestral home of the apple, and the wild Malus sieversii is considered a likely candidate for the ancestor of the modern domestic apple.
+
+ Ime potiče od reči алма, što na kazaškom jeziku znači "jabuka", i često se prevodi kao "pun jabuka". U suštini, region koji okružuje Almati se smatra pradomovinom jabuka, a divlja Malus sieversii se smatra mogućim pretkom moderne domaće jabuke.
>
);
@@ -73,59 +73,59 @@ h3, p { margin: 5px 0px; }
-Notice how pressing one panel's button does not affect the other panel--they are independent.
+Primetite kako pritiskanje dugmeta u jednom panel-u ne utiče na drugi--oni su nezavisni.
-
+
-Initially, each `Panel`'s `isActive` state is `false`, so they both appear collapsed
+Inicijalno, `isActive` state svakog `Panel`-a je `false`, tako da su oba sklopljena
-
+
-Clicking either `Panel`'s button will only update that `Panel`'s `isActive` state alone
+Klik na dugme bilo kog `Panel`-a će ažurirati samo `isActive` state tog `Panel`-a
-**But now let's say you want to change it so that only one panel is expanded at any given time.** With that design, expanding the second panel should collapse the first one. How would you do that?
+**Ali, recimo da to želite promeniti tako da samo jedan panel može biti proširen.** Sa takvim dizajnom, proširivanje drugog panel-a bi trebalo da sklopi prvi. Kako biste to uradili?
-To coordinate these two panels, you need to "lift their state up" to a parent component in three steps:
+Da biste koordinisali ta dva panel-a, potrebno je da "podignete njihov state" u roditeljsku komponentu u ova tri koraka:
-1. **Remove** state from the child components.
-2. **Pass** hardcoded data from the common parent.
-3. **Add** state to the common parent and pass it down together with the event handlers.
+1. **Ukloniti** state iz dečjih komponenata.
+2. **Proslediti** hardkodirane podatke iz zajedničkog roditelja.
+3. **Dodati** state u zajedničkog roditelja i proslediti ga zajedno sa event handler-ima.
-This will allow the `Accordion` component to coordinate both `Panel`s and only expand one at a time.
+Ovo će omogućiti `Accordion` komponenti da koordiniše oba `Panel`-a i proširi samo jedan.
-### Step 1: Remove state from the child components {/*step-1-remove-state-from-the-child-components*/}
+### Korak 1: Ukloniti state iz dečjih komponenata {/*step-1-remove-state-from-the-child-components*/}
-You will give control of the `Panel`'s `isActive` to its parent component. This means that the parent component will pass `isActive` to `Panel` as a prop instead. Start by **removing this line** from the `Panel` component:
+Daćete kontrolu nad `isActive` iz `Panel`-a njegovoj roditeljskoj komponenti. Ovo znači da će roditeljska komponenta proslediti `isActive` u `Panel` kao prop. Počnite sa **uklanjanjem ove linije** iz `Panel` komponente:
```js
const [isActive, setIsActive] = useState(false);
```
-And instead, add `isActive` to the `Panel`'s list of props:
+I umesto toga, dodajte `isActive` u listu props-a u `Panel`-u:
```js
function Panel({ title, children, isActive }) {
```
-Now the `Panel`'s parent component can *control* `isActive` by [passing it down as a prop.](/learn/passing-props-to-a-component) Conversely, the `Panel` component now has *no control* over the value of `isActive`--it's now up to the parent component!
+Sada roditeljska komponenta `Panel`-a može *kontrolisati* `isActive` [prosleđivanjem prop-a](/learn/passing-props-to-a-component). Sa druge strane, `Panel` komponenta sada *nema kontrolu* nad vrednošću `isActive`--sada je to na roditeljskoj komponenti!
-### Step 2: Pass hardcoded data from the common parent {/*step-2-pass-hardcoded-data-from-the-common-parent*/}
+### Korak 2: Proslediti hardkodirane podatke iz zajedničkog roditelja {/*step-2-pass-hardcoded-data-from-the-common-parent*/}
-To lift state up, you must locate the closest common parent component of *both* of the child components that you want to coordinate:
+Da biste podigli state morate locirati najbližu zajedničku roditeljsku komponentu *obe* dečje komponente koje želite da koordinišete:
-* `Accordion` *(closest common parent)*
+* `Accordion` *(najbliži zajednički roditelj)*
- `Panel`
- `Panel`
-In this example, it's the `Accordion` component. Since it's above both panels and can control their props, it will become the "source of truth" for which panel is currently active. Make the `Accordion` component pass a hardcoded value of `isActive` (for example, `true`) to both panels:
+U ovom primeru, to je `Accordion` komponenta. Pošto je iznad oba panel-a i može da kontroliše njihove props-e, postaće "izvor istine" označavajući koji panel je trenutno aktivan. Napravite da `Accordion` komponenta prosledi hardkodiranu vrednost za `isActive` (na primer, `true`) u oba panel-a:
@@ -135,12 +135,12 @@ import { useState } from 'react';
export default function Accordion() {
return (
<>
-
Almaty, Kazakhstan
-
- With a population of about 2 million, Almaty is Kazakhstan's largest city. From 1929 to 1997, it was its capital city.
+
Almati, Kazahstan
+
+ Sa populacijom od oko 2 miliona, Almati je najveći grad u Kazahstanu. Bio je glavni grad od 1929. do. 1997. godine.
-
- The name comes from алма, the Kazakh word for "apple" and is often translated as "full of apples". In fact, the region surrounding Almaty is thought to be the ancestral home of the apple, and the wild Malus sieversii is considered a likely candidate for the ancestor of the modern domestic apple.
+
+ Ime potiče od reči алма, što na kazaškom jeziku znači "jabuka", i često se prevodi kao "pun jabuka". U suštini, region koji okružuje Almati se smatra pradomovinom jabuka, a divlja Malus sieversii se smatra mogućim pretkom moderne domaće jabuke.
>
);
@@ -154,7 +154,7 @@ function Panel({ title, children, isActive }) {
{children}
) : (
)}
@@ -172,21 +172,21 @@ h3, p { margin: 5px 0px; }
-Try editing the hardcoded `isActive` values in the `Accordion` component and see the result on the screen.
+Pokušajte da promenite hardkodirane `isActive` vrednosti u `Accordion` komponenti da vidite rezultat na ekranu.
-### Step 3: Add state to the common parent {/*step-3-add-state-to-the-common-parent*/}
+### Korak 3: Dodati state u zajedničkog roditelja {/*step-3-add-state-to-the-common-parent*/}
-Lifting state up often changes the nature of what you're storing as state.
+Podizanje state-a često menja prirodu onoga što čuvate kao state.
-In this case, only one panel should be active at a time. This means that the `Accordion` common parent component needs to keep track of *which* panel is the active one. Instead of a `boolean` value, it could use a number as the index of the active `Panel` for the state variable:
+U ovom slučaju, samo jedan panel treba biti aktivan. To znači da zajednička roditeljska `Accordion` komponenta treba da prati *koji* panel je aktivan. Umesto `boolean` vrednosti može se koristiti broj kao indeks aktivnog `Panel`-a u state promenljivoj:
```js
const [activeIndex, setActiveIndex] = useState(0);
```
-When the `activeIndex` is `0`, the first panel is active, and when it's `1`, it's the second one.
+Kada je `activeIndex` jednak `0`, prvi panel je aktivan, a kada je `1`, aktivan je drugi.
-Clicking the "Show" button in either `Panel` needs to change the active index in `Accordion`. A `Panel` can't set the `activeIndex` state directly because it's defined inside the `Accordion`. The `Accordion` component needs to *explicitly allow* the `Panel` component to change its state by [passing an event handler down as a prop](/learn/responding-to-events#passing-event-handlers-as-props):
+Klik na dugme "Prikaži" u bilo kom `Panel`-u treba da promeni aktivan indeks u `Accordion`-u. `Panel` ne može da postavi `activeIndex` state direktno pošto je on definisan unutar `Accordion`-a. `Accordion` komponenta mora da *eksplicitno dozvoli* `Panel` komponenti da menja njen state [prosleđivanjem event handler-a kao prop-a](/learn/responding-to-events#passing-event-handlers-as-props):
```js
<>
@@ -205,7 +205,7 @@ Clicking the "Show" button in either `Panel` needs to change the active index in
>
```
-The `