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/sharing-state-between-components.md
+20-23
Original file line number
Diff line number
Diff line change
@@ -136,10 +136,10 @@ export default function Accordion() {
136
136
return (
137
137
<>
138
138
<h2>Алмати, Казахстан</h2>
139
-
<Panel title="About" isActive={true}>
139
+
<Panel title="Про Алмати" isActive={true}>
140
140
Із населенням близько 2 мільйонів, Алмати є найбільшим містом в Казахстані. З 1929 по 1997, воно було його столицею.
141
141
</Panel>
142
-
<Panel title="Etymology" isActive={true}>
142
+
<Panel title="Етимологія" isActive={true}>
143
143
Назва походить від казахського слова <span lang="kk-KZ">алма</span>, що означає "яблуко" і часто перекладалось як "повний яблук". Насправді, регіон що оточує Алмати вважається прабатьківщиною яблука, і дика <i lang="la">Malus sieversii</i> вважається ймовірним кандидатом на предка сучасного домашнього яблука.
144
144
</Panel>
145
145
</>
@@ -174,19 +174,18 @@ h3, p { margin: 5px 0px; }
174
174
175
175
Спробуйте відредагувати жорсткокодовані значення `isActive` у компоненті `Accordion` і подивіться на результат на екрані.
176
176
177
-
### Step 3: Add state to the common parent {/*step-3-add-state-to-the-common-parent*/}
177
+
### Крок 3: Добавте стан до батьківської компоненти {/*step-3-add-state-to-the-common-parent*/}
178
178
179
-
Lifting state up often changes the nature of what you're storing as state.
179
+
Підйом стану вгору часто змінює природу того, що ви зберігаєте як стан.
180
180
181
-
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:
181
+
В цьому випадку, тільки одна панель має бути актиною одночасно. Це означає що `Accordion`спільний батьківський компонент має відстежувати, *яка* панель є активною. Замість `boolean`значення, омжна використовувати число як індекс активної `Panel`для змінної стану:
182
182
183
183
```js
184
184
const [activeIndex, setActiveIndex] =useState(0);
185
185
```
186
+
Коли `activeIndex` доорівнює `0`, перша панель буде відкритою і коли це значення дорівнює `1`, активною буде друга.
186
187
187
-
When the `activeIndex` is `0`, the first panel is active, and when it's `1`, it's the second one.
188
-
189
-
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):
188
+
Натискаючи "Показати" кнопку в одній із `Panel` має змінити активний індекс в `Accordion`. `Panel` не може встановлювати `activeIndex` стан безпосередньо, оскільки це визанчається всередині `Accordion`. Компонент `Accordion` повинен *явно дозволити* компоненту `Panel` змінювати свій стан за допомогою [передавання обробника подій вниз як проп](/learn/responding-to-events#passing-event-handlers-as-props):
190
189
191
190
```js
192
191
<>
@@ -204,8 +203,7 @@ Clicking the "Show" button in either `Panel` needs to change the active index in
204
203
</Panel>
205
204
</>
206
205
```
207
-
208
-
The `<button>` inside the `Panel` will now use the `onShow` prop as its click event handler:
206
+
Кнопка `<button>` всередині `Panel` тепер буде використовувати `onShow` проп як обробник події кліку:
209
207
210
208
<Sandpack>
211
209
@@ -216,20 +214,20 @@ export default function Accordion() {
216
214
const [activeIndex, setActiveIndex] =useState(0);
217
215
return (
218
216
<>
219
-
<h2>Almaty, Kazakhstan</h2>
220
-
<Panel
221
-
title="About"
217
+
<h2>Алмати, Казахстан</h2>
218
+
<Panel
219
+
title="Про Алмати"
222
220
isActive={activeIndex ===0}
223
221
onShow={() =>setActiveIndex(0)}
224
222
>
225
-
With a population of about 2 million, Almaty is Kazakhstan's largest city. From 1929 to 1997, it was its capital city.
223
+
Із населенням близько 2 мільйонів, Алмати є найбільшим містом в Казахстані. З1929по1997, воно було його столицею.
226
224
</Panel>
227
225
<Panel
228
-
title="Etymology"
226
+
title="Етимологія"
229
227
isActive={activeIndex ===1}
230
228
onShow={() =>setActiveIndex(1)}
231
229
>
232
-
The name comes from <span lang="kk-KZ">алма</span>, 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 <i lang="la">Malus sieversii</i> is considered a likely candidate for the ancestor of the modern domestic apple.
230
+
Назва походить від казахського слова <span lang="kk-KZ">алма</span>, що означає "яблуко" і часто перекладалось як "повний яблук". Насправді, регіон що оточує Алмати вважається прабатьківщиною яблука, і дика <i lang="la">Malus sieversii</i>вважається ймовірним кандидатом на предка сучасного домашнього яблука.
233
231
</Panel>
234
232
</>
235
233
);
@@ -248,7 +246,7 @@ function Panel({
248
246
<p>{children}</p>
249
247
) : (
250
248
<button onClick={onShow}>
251
-
Show
249
+
Показати
252
250
</button>
253
251
)}
254
252
</section>
@@ -265,20 +263,19 @@ h3, p { margin: 5px 0px; }
265
263
```
266
264
267
265
</Sandpack>
268
-
269
-
This completes lifting state up! Moving state into the common parent component allowed you to coordinate the two panels. Using the active index instead of two "is shown" flags ensured that only one panel is active at a given time. And passing down the event handler to the child allowed the child to change the parent's state.
266
+
Підняття стану вгору завершено! Переміщення стану в спільний батьківський компонент дозволяє вам скоординувати дві панелі. Використовуючи активний індекс замість двох "показано" прапорців гарантує, що тільки одна панель буде активною на даний момент. І передаючи вниз обробник подій до дочірнього компонента дозволить дочірньому компоненту змінювати батьківський стан.
270
267
271
268
<DiagramGroup>
272
269
273
-
<Diagram name="sharing_state_parent" height={385} width={487} alt="Diagram showing a tree of three components, one parent labeled Accordion and two children labeled Panel. Accordion contains an activeIndex value of zero which turns into isActive value of true passed to the first Panel, and isActive value of false passed to the second Panel.">
270
+
<Diagram name="sharing_state_parent" height={385} width={487} alt="Діаграма зоображає дерево із трьох компонент, один батьківський з назвою Accordion та двох дочірніх з назвами Panel. Accordion містить activeIndex нульовим значенням, яке стає isActive із значенням true, що передається до першої панелі і isActive із значенням false до другої Panel.">
274
271
275
-
Initially, `Accordion`'s `activeIndex` is `0`, so the first `Panel` receives `isActive = true`
272
+
Початково, `Accordion` має `activeIndex`із значенням `0`, тому перша `Panel`отримує`isActive =true`
276
273
277
274
</Diagram>
278
275
279
-
<Diagram name="sharing_state_parent_clicked" height={385} width={521} alt="The same diagram as the previous, with the activeIndex value of the parent Accordion component highlighted indicating a click with the value changed to one. The flow to both of the children Panel components is also highlighted, and the isActive value passed to each child is set to the opposite: false for the first Panel and true for the second one." >
276
+
<Diagram name="sharing_state_parent_clicked" height={385} width={521} alt="Така сама діаграма що й попередня, тільки із activeIndex значення батьківського компонента підсвічено, що вказує клік із значенням зміненим на одиницю. Шлях до обох дочірніх Panel компонент таокж підсвічений та isActive значення, яке передане до кожної дочірньої компоненти є протилежним: false для першої Panel та true для другої" >
280
277
281
-
When `Accordion`'s`activeIndex`state changes to`1`, the second `Panel`receives`isActive = true`instead
278
+
Коли`Accordion``activeIndex`стан змінюється на`1`, друга `Panel`отримує`isActive =true`замість
0 commit comments