diff --git a/src/content/learn/sharing-state-between-components.md b/src/content/learn/sharing-state-between-components.md
index 52eaf28f8..d951cd99d 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: Поширення стану між компонентами
---
-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.
+Іноді вам потрібно, щоб стан двох компонентів завжди змінювався разом. Для цього видаліть стан з обох компонентів, перенесіть його до їхнього найближчого спільного батьківського компонента і потім передайте вниз до них через пропси. Це називається *підняттям стану вгору (lifting state up)*, і це одна з найпоширеніших речей, які ви будете робити під час написання React-коду.
-- How to share state between components by lifting it up
-- What are controlled and uncontrolled components
+- Як поширювати стан між компонентами підняттям його вгору
+- Що таке контрольовані та неконтрольовані компоненти
-## Lifting state up by example {/*lifting-state-up-by-example*/}
+## Підняття стану на прикладі {/*lifting-state-up-by-example*/}
-In this example, a parent `Accordion` component renders two separate `Panel`s:
+У цьому прикладі батьківський компонент `Accordion` рендерить два окремих компонента-панелі `Panel`:
* `Accordion`
- `Panel`
- `Panel`
-Each `Panel` component has a boolean `isActive` state that determines whether its content is visible.
+Кожний компонент `Panel` має булевий стан `isActive`, який визначає, чи його вміст видимий.
-Press the Show button for both panels:
+Натисніть кнопку "Показати" для обох панелей:
@@ -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.
+
Алмати, Казахстан
+
+ З майже 2-мільйонним населеннм Алмати є найбільшим містом в Казахстані. З 1929 до 1997 воно було його столицею.
-
- 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.
+
+ Назва походить від казахського слова алма, що означає "яблуко" і часто перекладалось як "повний яблук". Насправді регіон, який оточує Алмати вважається прабатьківщиною яблука, а дика Malus sieversii - ймовірним кандидатом на предка сучасного домашнього яблука.
>
);
@@ -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.
+Зверніть увагу, що натискання кнопки однієї панелі не впливає на іншу панель -- вони незалежні.
-
+
-Initially, each `Panel`'s `isActive` state is `false`, so they both appear collapsed
+Спочатку стан `isActive` кожного `Panel` дорівнює `false`, тому обидва мають згорнутий вигляд
-
+
-Clicking either `Panel`'s button will only update that `Panel`'s `isActive` state alone
+Натискання на будь-яку з кнопок `Panel` призведе до оновлення стану `isActive` тільки цієї `Panel`
-**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?
+**Але тепер припустимо, що ви хочете змінити це так, щоб тільки одна панель була розгорнута в будь-який момент часу.** За цього дизайну розгортання другої панелі повинно згорнути першу. Як би ви це зробили?
-To coordinate these two panels, you need to "lift their state up" to a parent component in three steps:
+Щоб скоординувати ці дві панелі, вам потрібно "підняти їхній стан вгору" до батьківського компонента в три кроки:
-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. **Видалити** стан із дочірніх компонентів.
+2. **Передати** незмінні дані від спільного батьківського компонента.
+3. **Додати** стан до спільного батька і передати його вниз разом з обробниками подій.
-This will allow the `Accordion` component to coordinate both `Panel`s and only expand one at a time.
+Це дасть компоненту `Accordion` змогу скоординувати обидва компоненти `Panel` та розгортати тільки один щоразу.
-### Step 1: Remove state from the child components {/*step-1-remove-state-from-the-child-components*/}
+### Крок 1: Видаліть стан із дочірніх компонентів {/*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:
+Ви передасте контроль `isActive` компонента `Panel` його батьківському компоненту. Це означає, що батьківський компонент передасть `isActive` дочірньому `Panel` як проп. Почніть із **видалення цього рядка** з `Panel`:
```js
const [isActive, setIsActive] = useState(false);
```
-And instead, add `isActive` to the `Panel`'s list of props:
+Натомість додайте `isActive` до списку пропсів `Panel`:
```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!
+Тепер батьківський компонент `Panel` може *контролювати* `isActive`, [передаючи його як проп.](/learn/passing-props-to-a-component) І навпаки: `Panel` тепер *не має контролю* над значенням `isActive` -- тепер це залежить від батьківського компонента!
-### Step 2: Pass hardcoded data from the common parent {/*step-2-pass-hardcoded-data-from-the-common-parent*/}
+### Крок 2: Передайте незмінні дані від спільного батьківського компонента {/*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:
+Щоб підняти стан вгору, ви повинні виявити найближчий спільний батьківський компонент *обох* дочірніх компонентів, які ви хочете скоординувати:
-* `Accordion` *(closest common parent)*
+* `Accordion` *(найближчий спільний батько)*
- `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:
+У цьому прикладі ним є компонент `Accordion`. Оскільки він знаходиться над обома панелями і може контролювати їхні пропси, він стане "джерелом правди" для визначення того, яка панель є наразі відкритою. Зробіть так, щоб компонент `Accordion` передавав незмінне значення `isActive` (наприклад, `true`) до обох панелей:
@@ -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.
+
Алмати, Казахстан
+
+ З майже 2-мільйонним населеннм Алмати є найбільшим містом в Казахстані. З 1929 до 1997 воно було його столицею.
-
- 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.
+
+ Назва походить від казахського слова алма, що означає "яблуко" і часто перекладалось як "повний яблук". Насправді регіон, який оточує Алмати вважається прабатьківщиною яблука, а дика Malus sieversii - ймовірним кандидатом на предка сучасного домашнього яблука.
>
);
@@ -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.
+Спробуйте відредагувати жорсткокодовані значення `isActive` у компоненті `Accordion` та подивіться результат на екрані.
-### Step 3: Add state to the common parent {/*step-3-add-state-to-the-common-parent*/}
+### Крок 3: Добавте стан до батьківської компоненти {/*step-3-add-state-to-the-common-parent*/}
-Lifting state up often changes the nature of what you're storing as 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:
+В цьому випадку, тільки одна панель має бути активною на даний момент. Це означає що `Accordion` спільний батьківський компонент має відстежувати, *яка* панель є активною. Замість `boolean` значення, можна використовувати число як індекс активної `Panel` для змінної стану:
```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.
+Коли `activeIndex` доорівнює `0`, перша панель буде відкритою і коли це значення дорівнює `1`, активною буде друга.
-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):
+Натискаючи "Показати" кнопку в одній із `Panel` має змінити активний індекс в `Accordion`. `Panel` не може встановлювати `activeIndex` стан безпосередньо, оскільки це визанчається всередині `Accordion`. Компонент `Accordion` повинен *явно дозволити* компоненту `Panel` змінювати свій стан за допомогою [передавання обробника подій вниз як проп](/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 `