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
При використанні порталів, важливо впевнитись, що ваш застосунок залишається доступним для користувачів з обмеженими можливостями. Приміром, вам може знадобитись функціонал для управління фокусом клавіатури, щоб користувач міг переміщати фокус клавіатури в та з порталу у звичний спосіб.
242
242
243
-
<<<<<<< HEAD
244
-
Слідуйте [WAI-ARIA Modal Authoring Practices](https://www.w3.org/WAI/ARIA/apg/#dialog_modal) коли створюєте модальні вікна. Якщо ви використовуєте пакет для модальних вікон від спільноти, переконайтеся, що він відповідає цим рекомендація та доступний користувачам з обмеженими можливостями.
245
-
=======
246
-
Follow the [WAI-ARIA Modal Authoring Practices](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal) when creating modals. If you use a community package, ensure that it is accessible and follows these guidelines.
247
-
>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
243
+
Коли розроблюєте модальні вікна, дотримуйтеся відповідних[практик WAI-ARIA](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal). Якщо ви використовуєте пакет для модальних вікон від спільноти, переконайтеся, що він керується цими рекомендаціями та є доступним для всіх.
Copy file name to clipboardExpand all lines: src/content/reference/react/useContext.md
+5-47Lines changed: 5 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,23 +38,13 @@ function MyComponent() {
38
38
39
39
#### Результат {/*returns*/}
40
40
41
-
<<<<<<< HEAD
42
-
`useContext` повертає значення контексту для компонента, що викликає цей хук. Це значення визначається як `value`, передане найближчому `SomeContext.Provider`, розташованому вище деревом відносно поточного компонента. Якщо такого провайдера немає, повертається значення `defaultValue`, яке ви передали функції [`createContext`](/reference/react/createContext). Повернуте значення завжди актуальне. React автоматично повторно рендерить усі компоненти, що використовують контекст, якщо значення контексту змінюється.
43
-
=======
44
-
`useContext` returns the context value for the calling component. It is determined as the `value` passed to the closest `SomeContext` above the calling component in the tree. If there is no such provider, then the returned value will be the `defaultValue` you have passed to [`createContext`](/reference/react/createContext) for that context. The returned value is always up-to-date. React automatically re-renders components that read some context if it changes.
45
-
>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
41
+
`useContext` повертає значення контексту для компонента, що викликає цей хук. Це значення визначається як `value`, передане найближчому `SomeContext`, розташованому вище деревом відносно поточного компонента. Якщо такого провайдера немає, повертається значення `defaultValue`, яке ви передали функції [`createContext`](/reference/react/createContext). Повернуте значення завжди актуальне. React автоматично повторно рендерить усі компоненти, що використовують контекст, якщо значення контексту змінюється.
46
42
47
43
#### Застереження {/*caveats*/}
48
44
49
-
<<<<<<< HEAD
50
-
* Eлементи-провайдери не впливають на виклик `useContext()` у компоненті, з якого й повертаються. Відповідний `<Context.Provider>` **повинен бути розташований *вище*** компонента, що викликає `useContext()`.
45
+
* Eлементи-провайдери не впливають на виклик `useContext()` у компоненті, з якого й повертаються. Відповідний `<Context>` **повинен бути розташований *вище*** компонента, що викликає `useContext()`.
51
46
* React **автоматично оновлює** всі дочірні компоненти, які використовують певний контекст, починаючи з провайдера, що отримує змінене значення `value`. Попереднє та наступне значення порівнюються за допомогою [`Object.is`](https://webdoky.org/uk/docs/Web/JavaScript/Reference/Global_Objects/Object/is/). Пропуск повторних рендерів за допомогою [`memo`](/reference/react/memo) не заважає дочірнім компонентам отримувати оновлене значення контексту.
52
47
* Якщо ваша система збирання створює дублікати модулів у вихідному коді (що може статися через символьні посилання), це може порушити контекст. Передавання через контекст працює тільки у разі, якщо `SomeContext` для надання контексту та `SomeContext` для його зчитування є ***точно* тим самим об'єктом**, що визначається порівнянням `===`.
53
-
=======
54
-
* `useContext()` call in a component is not affected by providers returned from the *same* component. The corresponding `<Context>` **needs to be *above*** the component doing the `useContext()` call.
55
-
* React **automatically re-renders** all the children that use a particular context starting from the provider that receives a different `value`. The previous and the next values are compared with the [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) comparison. Skipping re-renders with [`memo`](/reference/react/memo) does not prevent the children receiving fresh context values.
56
-
* If your build system produces duplicates modules in the output (which can happen with symlinks), this can break context. Passing something via context only works if `SomeContext` that you use to provide context and `SomeContext` that you use to read it are ***exactly* the same object**, as determined by a `===` comparison.
57
-
>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
58
48
59
49
---
60
50
@@ -1111,17 +1101,10 @@ export default function MyApp() {
1111
1101
1112
1102
function Form() {
1113
1103
return (
1114
-
<<<<<<< HEAD
1115
1104
<Panel title="Ласкаво просимо">
1116
1105
<Button>Зареєструватися</Button>
1117
1106
<Button>Увійти</Button>
1118
-
<ThemeContext.Provider value="light">
1119
-
=======
1120
-
<Panel title="Welcome">
1121
-
<Button>Sign up</Button>
1122
-
<Button>Log in</Button>
1123
1107
<ThemeContext value="light">
1124
-
>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
1125
1108
<Footer />
1126
1109
</ThemeContext>
1127
1110
</Panel>
@@ -1366,28 +1349,17 @@ function MyApp() {
1366
1349
1367
1350
Існує кілька поширених причин, чому це може статися:
1368
1351
1369
-
<<<<<<<HEAD
1370
-
1. Ви розміщуєте `<SomeContext.Provider>` у тому ж компоненті або нижче, ніж компонент, де викликано `useContext()`. Перемістіть `<SomeContext.Provider>`*вище і зовні* компонента, який викликає `useContext()`.
1371
-
2. Можливо, ви забули обгорнути свій компонент у `<SomeContext.Provider>` або розмістили його в іншій, ніж задумали, частині дерева. Переконайтеся за допомогою [React DevTools](/learn/react-developer-tools), що ієрархія компонентів налаштована правильно.
1352
+
1. Ви розміщуєте `<SomeContext>` у тому ж компоненті або нижче, ніж компонент, де викликано `useContext()`. Перемістіть `<SomeContext>`*вище і зовні* компонента, який викликає `useContext()`.
1353
+
2. Можливо, ви забули обгорнути свій компонент у `<SomeContext>` або розмістили його в іншій, ніж задумали, частині дерева. Переконайтеся за допомогою [React DevTools](/learn/react-developer-tools), що ієрархія компонентів налаштована правильно.
1372
1354
3. Можливо, ви зіткнулися з проблемою збирання, через яку `SomeContext` із компонента-провайдера і `SomeContext` компонента-читача є різними об'єктами. Це може статися, наприклад, якщо ви використовуєте символьні посилання. Можете перевірити це, присвоївши їх глобальним змінним, як-от `window.SomeContext1` і `window.SomeContext2`, а потім порівняти `window.SomeContext1 === window.SomeContext2` в консолі. Якщо вони не тотожні, виправте цю проблему на рівні збирання.
1373
-
=======
1374
-
1. You're rendering `<SomeContext>`in the same component (or below) as where you're calling `useContext()`. Move `<SomeContext>` *above and outside* the component calling `useContext()`.
1375
-
2. You may have forgotten to wrap your component with `<SomeContext>`, or you might have put it in a different part of the tree than you thought. Check whether the hierarchy is right using [React DevTools.](/learn/react-developer-tools)
1376
-
3. You might be running into some build issue with your tooling that causes `SomeContext` as seen from the providing component and `SomeContext` as seen by the reading component to be two different objects. This can happen if you use symlinks, for example. You can verify this by assigning them to globals like `window.SomeContext1` and `window.SomeContext2` and then checking whether `window.SomeContext1 === window.SomeContext2` in the console. If they're not the same, fix that issue on the build tool level.
1377
-
>>>>>>>50d6991ca6652f4bc4c985cf0c0e593864f2cc91
1378
1355
1379
1356
### Я завжди отримую `undefined` із контексту, хоча початкове значення інше {/*i-am-always-getting-undefined-from-my-context-although-the-default-value-is-different*/}
1380
1357
1381
1358
Можливо, у вас є провайдер без `value` у дереві:
1382
1359
1383
1360
```js {1,2}
1384
-
<<<<<<< HEAD
1385
1361
// 🚩 Не працює: немає пропа value
1386
-
<ThemeContext.Provider>
1387
-
=======
1388
-
// 🚩 Doesn't work: no value prop
1389
1362
<ThemeContext>
1390
-
>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
1391
1363
<Button />
1392
1364
</ThemeContext>
1393
1365
```
@@ -1397,33 +1369,19 @@ function MyApp() {
1397
1369
Також, можливо, ви випадково застосували помилкову назву пропа:
1398
1370
1399
1371
```js {1,2}
1400
-
<<<<<<< HEAD
1401
1372
// 🚩 Не працює: проп має називатися "value"
1402
-
<ThemeContext.Provider theme={theme}>
1403
-
=======
1404
-
// 🚩 Doesn't work: prop should be called "value"
1405
1373
<ThemeContext theme={theme}>
1406
-
>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
1407
1374
<Button />
1408
1375
</ThemeContext>
1409
1376
```
1410
1377
1411
1378
В обох випадках React покаже попередження у консолі. Щоб виправити це, назвіть проп `value`:
1412
1379
1413
1380
```js {1,2}
1414
-
<<<<<<< HEAD
1415
1381
// ✅ Передача пропа value
1416
-
<ThemeContext.Provider value={theme}>
1417
-
=======
1418
-
// ✅ Passing the value prop
1419
1382
<ThemeContext value={theme}>
1420
-
>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
1421
1383
<Button />
1422
1384
</ThemeContext>
1423
1385
```
1424
1386
1425
-
<<<<<<<HEAD
1426
-
Зверніть увагу, що [початкове значення, яке ви передали у `createContext(defaultValue)`](#specifying-a-fallback-default-value), застосовується, **тільки якщо вище в ієрархії не знайдено жодного провайдера.** Якщо в будь-якому місці дерева батьківських компонентів є `<SomeContext.Provider value={undefined}>`, компонент, що викликає `useContext(SomeContext)`, *отримає*`undefined` як значення контексту.
1427
-
=======
1428
-
Note that the [default value from your `createContext(defaultValue)` call](#specifying-a-fallback-default-value) is only used **if there is no matching provider above at all.** If there is a `<SomeContext value={undefined}>` component somewhere in the parent tree, the component calling `useContext(SomeContext)`*will* receive `undefined` as the context value.
1429
-
>>>>>>>50d6991ca6652f4bc4c985cf0c0e593864f2cc91
1387
+
Зверніть увагу, що [початкове значення, яке ви передали у `createContext(defaultValue)`](#specifying-a-fallback-default-value), застосовується, **тільки якщо вище в ієрархії не знайдено жодного провайдера.** Якщо в будь-якому місці дерева батьківських компонентів є `<SomeContext value={undefined}>`, компонент, що викликає `useContext(SomeContext)`, *отримає* `undefined` як значення контексту.
0 commit comments