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/reference/react/Fragment.md
+29-29
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: <Fragment> (<>...</>)
4
4
5
5
<Intro>
6
6
7
-
`<Fragment>`, often used via `<>...</>` syntax, lets you group elements without a wrapper node.
7
+
`<Fragment>`, часто використовується за допомогою синтаксису `<>...</>`, дозволяє групувати елементи без елементу-обгортки.
8
8
9
9
```js
10
10
<>
@@ -19,29 +19,29 @@ title: <Fragment> (<>...</>)
19
19
20
20
---
21
21
22
-
## Reference {/*reference*/}
22
+
## Опис {/*reference*/}
23
23
24
24
### `<Fragment>` {/*fragment*/}
25
25
26
-
Wrap elements in`<Fragment>`to group them together in situations where you need a single element. Grouping elements in`Fragment`has no effect on the resulting DOM; it is the same as if the elements were not grouped. The empty JSX tag `<></>`is shorthand for`<Fragment></Fragment>` in most cases.
26
+
Огорніть елементи у`<Fragment>`щоб групувати їх разом в ситуаціях, коли вам потрібен один елемент. Групування елементів у`Fragment`не впливає на результуючий DOM; це так само, ніби елементи і не були згруповані. Переважно, порожній тег JSX `<></>`є скороченням для`<Fragment></Fragment>`.
27
27
28
-
#### Props {/*props*/}
28
+
#### Пропси {/*props*/}
29
29
30
-
-**optional**`key`: Fragments declared with the explicit`<Fragment>`syntax may have [keys.](/learn/rendering-lists#keeping-list-items-in-order-with-key)
30
+
-**опційний**`key`: Фрагменти, оголошені з явним синтаксисом`<Fragment>`можуть мати [ключі.](/learn/rendering-lists#keeping-list-items-in-order-with-key)
31
31
32
-
#### Caveats {/*caveats*/}
32
+
#### Обмеження {/*caveats*/}
33
33
34
-
-If you want to pass `key`to a Fragment, you can't use the `<>...</>` syntax. You have to explicitly import `Fragment`from`'react'`and render`<Fragment key={yourKey}>...</Fragment>`.
34
+
-Якщо ви хочете передати `key`для Fragment, ви не можете використовувати синтаксис `<>...</>`. Ви маєте явно імпортувати `Fragment`з`'react'`та рендерити`<Fragment key={yourKey}>...</Fragment>`.
35
35
36
-
- React does not [reset state](/learn/preserving-and-resetting-state)when you go from rendering `<><Child /></>`to`[<Child />]`or back, or when you go from rendering`<><Child /></>`to`<Child />`and back. This only works a single level deep: for example, going from`<><><Child /></></>`to`<Child />`resets the state. See the precise semantics [here.](https://gist.github.com/clemmy/b3ef00f9507909429d8aa0d3ee4f986b)
36
+
- React не буде [скидати стан](/learn/preserving-and-resetting-state)компонента коли ви переходите від рендерингу `<><Child /></>`до`[<Child />]`або назад, або коли ви переходите від рендерингу`<><Child /></>`до`<Child />`і назад. Це може працювати лише на одному рівні вкладеності: наприклад, перехід від`<><><Child /></></>`до`<Child />`скидає стан компонента. Дивіться точну семантику [тут.](https://gist.github.com/clemmy/b3ef00f9507909429d8aa0d3ee4f986b)
37
37
38
38
---
39
39
40
-
## Usage {/*usage*/}
40
+
## Використання {/*usage*/}
41
41
42
-
### Returning multiple elements {/*returning-multiple-elements*/}
42
+
### Повернення кількох елементів {/*returning-multiple-elements*/}
43
43
44
-
Use`Fragment`, or the equivalent`<>...</>` syntax, to group multiple elements together. You can use it to put multiple elements in any place where a single element can go. For example, a component can only return one element, but by using a Fragment you can group multiple elements together and then return them as a group:
44
+
Використовуйте`Fragment`, або еквівалентний синтаксис`<>...</>`, для групування кількох елементів разом. Ви можете використовувати його для збору кількох елементів в будь-якому місці, де може бути один елемент. Наприклад, компонент може повернути тільки один елемент, але за допомогою Fragment ви можете групувати кілька елементів разом і повертати їх як групу:
45
45
46
46
```js {3,6}
47
47
functionPost() {
@@ -54,16 +54,16 @@ function Post() {
54
54
}
55
55
```
56
56
57
-
Fragments are useful because grouping elements with a Fragment has no effect on layout or styles, unlike if you wrapped the elements in another container like a DOM element. If you inspect this example with the browser tools, you'll see that all `<h1>`and`<p>`DOM nodes appear as siblings without wrappers around them:
57
+
Фрагменти є корисним інструментом, оскільки групування елементів з `Fragment` не має впливу на розташування або стилізацію, на відміну від огортання елементів в інший контейнер, такий як DOM-елемент. Якщо ви перевірите цей приклад за допомогою інструментів браузера, ви побачите, що всі DOM-вузли `<h1>`і`<p>`відображаються як сусідні елементи без обгорток навколо них:
58
58
59
59
<Sandpack>
60
60
61
61
```js
62
62
exportdefaultfunctionBlog() {
63
63
return (
64
64
<>
65
-
<Post title="An update" body="It's been a while since I posted..."/>
66
-
<Post title="My new blog" body="I am starting a new blog!"/>
65
+
<Post title="Оновлення" body="Минув деякий час після мого останнього повідомлення..."/>
66
+
<Post title="Мій новий блог" body="Я розпочинаю новий блог!"/>
67
67
</>
68
68
)
69
69
}
@@ -94,9 +94,9 @@ function PostBody({ body }) {
94
94
95
95
<DeepDive>
96
96
97
-
#### How to write a Fragment without the special syntax? {/*how-to-write-a-fragment-without-the-special-syntax*/}
97
+
#### Як написати Fragment без спеціального синтаксису? {/*how-to-write-a-fragment-without-the-special-syntax*/}
98
98
99
-
The example above is equivalent to importing `Fragment`from React:
99
+
Цей приклад еквівалентний імпорту `Fragment`з React:
100
100
101
101
```js {1,5,8}
102
102
import { Fragment } from'react';
@@ -111,15 +111,15 @@ function Post() {
111
111
}
112
112
```
113
113
114
-
Usually you won't need this unless you need to [pass a `key`to your`Fragment`.](#rendering-a-list-of-fragments)
114
+
Зазвичай вам не потрібно цього робити, якщо вам не треба [передавати `key`у ваш`Fragment`.](#rendering-a-list-of-fragments)
115
115
116
116
</DeepDive>
117
117
118
118
---
119
119
120
-
### Assigning multiple elements to a variable {/*assigning-multiple-elements-to-a-variable*/}
120
+
### Присвоєння змінній декількох елементів {/*assigning-multiple-elements-to-a-variable*/}
121
121
122
-
Like any other element, you can assign Fragment elements to variables, pass them as props, and so on:
122
+
Як і будь-який інший елемент, `Fragment` елементи можна присвоювати змінним, передавати їх як пропси тощо:
123
123
124
124
```js
125
125
functionCloseDialog() {
@@ -131,25 +131,25 @@ function CloseDialog() {
131
131
);
132
132
return (
133
133
<AlertDialog buttons={buttons}>
134
-
Are you sure you want to leave this page?
134
+
Ви впевнені, що хочете залишити цю сторінку?
135
135
</AlertDialog>
136
136
);
137
137
}
138
138
```
139
139
140
140
---
141
141
142
-
### Grouping elements with text {/*grouping-elements-with-text*/}
142
+
### Групування елементів з текстом {/*grouping-elements-with-text*/}
143
143
144
-
You can use`Fragment` to group text together with components:
144
+
Ви можете використовувати`Fragment`, щоб групувати текст разом з компонентами:
145
145
146
146
```js
147
147
functionDateRangePicker({ start, end }) {
148
148
return (
149
149
<>
150
-
From
150
+
Від
151
151
<DatePicker date={start} />
152
-
to
152
+
до
153
153
<DatePicker date={end} />
154
154
</>
155
155
);
@@ -158,9 +158,9 @@ function DateRangePicker({ start, end }) {
158
158
159
159
---
160
160
161
-
### Rendering a list of Fragments {/*rendering-a-list-of-fragments*/}
161
+
### Відображення списку фрагментів {/*rendering-a-list-of-fragments*/}
162
162
163
-
Here's a situation where you need to write `Fragment`explicitly instead of using the `<></>` syntax. When you [render multiple elements in a loop](/learn/rendering-lists), you need to assign a `key`to each element. If the elements within the loop are Fragments, you need to use the normal JSX element syntax in order to provide the `key` attribute:
163
+
Ось ситуація, коли вам потрібно написати `Fragment`явно, замість використання синтаксису `<></>`. Якщо ви [рендерите кілька елементів в циклі](/learn/rendering-lists), вам потрібно призначити `key`кожному елементу. Якщо елементи всередині циклу є Фрагментами, то вам потрібно використовувати звичайний синтаксис елементів JSX, щоб мати змогу вказати атрибут `key`:
164
164
165
165
```js {3,6}
166
166
functionBlog() {
@@ -173,16 +173,16 @@ function Blog() {
173
173
}
174
174
```
175
175
176
-
You can inspect the DOM to verify that there are no wrapper elements around the Fragment children:
176
+
Ви можете перевірити DOM, щоб переконатися, що дочірні компоненти Fragment нічим не обгортуються:
177
177
178
178
<Sandpack>
179
179
180
180
```js
181
181
import { Fragment } from'react';
182
182
183
183
constposts= [
184
-
{ id:1, title:'An update', body:"It's been a while since I posted..." },
185
-
{ id:2, title:'My new blog', body:'I am starting a new blog!' }
184
+
{ id:1, title:'Оновлення', body:"Минув деякий час після мого останнього повідомлення..." },
185
+
{ id:2, title:'Мій новий блог', body:'Я розпочинаю новий блог!' }
0 commit comments