Skip to content

Commit 2bd8a1d

Browse files
westanvvvldmrkl
authored andcommitted
Components and Props (#10)
* Started translation * Deleted comments, finished translation * Changed wording * Changed wording
1 parent 9611f6e commit 2bd8a1d

File tree

2 files changed

+59
-59
lines changed

2 files changed

+59
-59
lines changed

content/docs/components-and-props.md

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: components-and-props
3-
title: Components and Props
3+
title: Компоненти і пропси
44
permalink: docs/components-and-props.html
55
redirect_from:
66
- "docs/reusable-components.html"
@@ -16,98 +16,98 @@ prev: rendering-elements.html
1616
next: state-and-lifecycle.html
1717
---
1818

19-
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This page provides an introduction to the idea of components. You can find a [detailed component API reference here](/docs/react-component.html).
19+
Компоненти дозволяють розділити інтерфейс користувача на незалежні частини, придатні до повторного використання, і сприймати їх як такі, що функціонують окремо один від одного. На цій сторінці викладений вступ до ідеї компонентів. Ви можете знайти [докладний опис API компонентів тут](/docs/react-component.html).
2020

21-
Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called "props") and return React elements describing what should appear on the screen.
21+
Концептуально компоненти є подібними до функцій JavaScript. Вони приймають довільні вхідні дані (так звані "пропси") і повертають React-елементи, що описують те, що повинно з'явитися на екрані.
2222

23-
## Function and Class Components {#function-and-class-components}
23+
## Функціональні та класові компоненти {#function-and-class-components}
2424

25-
The simplest way to define a component is to write a JavaScript function:
25+
Найпростішим способом визначення компонента є написання функції JavaScript:
2626

2727
```js
2828
function Welcome(props) {
29-
return <h1>Hello, {props.name}</h1>;
29+
return <h1>Привіт, {props.name}</h1>;
3030
}
3131
```
3232

33-
This function is a valid React component because it accepts a single "props" (which stands for properties) object argument with data and returns a React element. We call such components "function components" because they are literally JavaScript functions.
33+
Ця функція є валідним React-компонентом, оскільки вона приймає єдиний аргумент "пропс" (скорочено від _properties_ - властивості), який є об'єктом з даними і повертає React-елемент. Такі компоненти ми називаємо "функціональними компонентами", оскільки вони буквально є JavaScript функціями.
3434

35-
You can also use an [ES6 class](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes) to define a component:
35+
Ви також можете використовувати [ES6 класи](https://developer.mozilla.org/uk/docs/Web/JavaScript/Reference/Classes), щоб визначити компонент:
3636

3737
```js
3838
class Welcome extends React.Component {
3939
render() {
40-
return <h1>Hello, {this.props.name}</h1>;
40+
return <h1>Привіт, {this.props.name}</h1>;
4141
}
4242
}
4343
```
4444

45-
The above two components are equivalent from React's point of view.
45+
Два компоненти, що наведені вище, є еквівалентними з точки зору React.
4646

47-
Classes have some additional features that we will discuss in the [next sections](/docs/state-and-lifecycle.html). Until then, we will use function components for their conciseness.
47+
Класи мають деякі додаткові особливості, які ми обговоримо в [наступних розділах](/docs/state-і-lifecycle.html). До тих пір ми будемо використовувати функціональні компоненти через їх лаконічність.
4848

49-
## Rendering a Component {#rendering-a-component}
49+
## Рендеринг компонентів {#rendering-a-component}
5050

51-
Previously, we only encountered React elements that represent DOM tags:
51+
Раніше ми зустрічали лише React-елементи, які представляють теги DOM:
5252

5353
```js
5454
const element = <div />;
5555
```
5656

57-
However, elements can also represent user-defined components:
57+
Однак елементи можуть також представляти визначені користувачем компоненти:
5858

5959
```js
60-
const element = <Welcome name="Sara" />;
60+
const element = <Welcome name="Василина" />;
6161
```
6262

63-
When React sees an element representing a user-defined component, it passes JSX attributes to this component as a single object. We call this object "props".
63+
Коли React бачить елемент, що представляє визначений користувачем компонент, він передає атрибути JSX цьому компоненту як єдиний об'єкт. Ми називаємо цей об'єкт "пропси".
6464

65-
For example, this code renders "Hello, Sara" on the page:
65+
Наприклад, код нижче виводить на сторінці "Привіт, Василина":
6666

6767
```js{1,5}
6868
function Welcome(props) {
69-
return <h1>Hello, {props.name}</h1>;
69+
return <h1>Привіт, {props.name}</h1>;
7070
}
7171
72-
const element = <Welcome name="Sara" />;
72+
const element = <Welcome name="Василина" />;
7373
ReactDOM.render(
7474
element,
7575
document.getElementById('root')
7676
);
7777
```
7878

79-
[](codepen://components-and-props/rendering-a-component)
79+
[Спробуйте на CodePen](codepen://components-and-props/rendering-a-component)
8080

81-
Let's recap what happens in this example:
81+
Давайте розберемо, що відбувається в цьому прикладі:
8282

83-
1. We call `ReactDOM.render()` with the `<Welcome name="Sara" />` element.
84-
2. React calls the `Welcome` component with `{name: 'Sara'}` as the props.
85-
3. Our `Welcome` component returns a `<h1>Hello, Sara</h1>` element as the result.
86-
4. React DOM efficiently updates the DOM to match `<h1>Hello, Sara</h1>`.
83+
1. Ми викликаємо `ReactDOM.render()` з елементом `<Welcome name="Василина" />`.
84+
2. React викликає компонент `Welcome` з пропсом `{name: 'Василина'}`.
85+
3. `Welcome` компонент повертає елемент `<h1>Привіт, Василина</h1>`.
86+
4. React DOM ефективно оновлює DOM для отримання `<h1>Привіт, Василина</h1>`.
8787

88-
>**Note:** Always start component names with a capital letter.
88+
>**Примітка:** Завжди починайте писати імена компонентів з великої літери.
8989
>
90-
>React treats components starting with lowercase letters as DOM tags. For example, `<div />` represents an HTML div tag, but `<Welcome />` represents a component and requires `Welcome` to be in scope.
90+
>React розглядає компоненти, що починаються з малих літер, як теги DOM. Наприклад, `<div />` представляє тег HTML div, але `<Welcome />` являє собою компонент і вимагає, щоб `Welcome` знаходився в області застосування.
9191
>
92-
>To learn more about the reasoning behind this convention, please read [JSX In Depth](/docs/jsx-in-depth.html#user-defined-components-must-be-capitalized).
92+
>Щоб дізнатися більше про причини такої поведінки, прочитайте [Поглиблений розгляд JSX](/docs/jsx-in-depth.html#user-defined-components-must-be-capitalized).
9393
94-
## Composing Components {#composing-components}
94+
## Композиція компонентів {#composing-components}
9595

96-
Components can refer to other components in their output. This lets us use the same component abstraction for any level of detail. A button, a form, a dialog, a screen: in React apps, all those are commonly expressed as components.
96+
Компоненти можуть посилатися на інші компоненти під час виведення. Це дозволяє нам використовувати одну і ту ж абстракцію компонентів для будь-якого рівня деталізації. Кнопка, форма, діалогове вікно, екран: у React-додатках всі вони зазвичай виражаються як компоненти.
9797

98-
For example, we can create an `App` component that renders `Welcome` many times:
98+
Наприклад, ми можемо створити компонент `App`, що відрендерить компонент `Welcome` багато разів:
9999

100100
```js{8-10}
101101
function Welcome(props) {
102-
return <h1>Hello, {props.name}</h1>;
102+
return <h1>Привіт, {props.name}</h1>;
103103
}
104104
105105
function App() {
106106
return (
107107
<div>
108-
<Welcome name="Sara" />
109-
<Welcome name="Cahal" />
110-
<Welcome name="Edite" />
108+
<Welcome name="Василина" />
109+
<Welcome name="Михайло" />
110+
<Welcome name="Вадим" />
111111
</div>
112112
);
113113
}
@@ -118,15 +118,15 @@ ReactDOM.render(
118118
);
119119
```
120120

121-
[](codepen://components-and-props/composing-components)
121+
[Спробуйте на CodePen](codepen://components-and-props/composing-components)
122122

123-
Typically, new React apps have a single `App` component at the very top. However, if you integrate React into an existing app, you might start bottom-up with a small component like `Button` and gradually work your way to the top of the view hierarchy.
123+
Як правило, нові React-додатки мають єдиний компонент `App`, що знаходиться зверху дерева ієрархій елементів. Однак, якщо ви інтегруєте React у існуючий додаток, ви можете почати знизу вгору з невеликим компонентом, наприклад `Button`, і поступово працювати у верхній частині ієрархії перегляду.
124124

125-
## Extracting Components {#extracting-components}
125+
## Розбиття компонентів на частини {#extracting-components}
126126

127-
Don't be afraid to split components into smaller components.
127+
Не бійтеся розбивати компоненти на дрібніші компоненти.
128128

129-
For example, consider this `Comment` component:
129+
Наприклад, розглянемо компонент `Comment`:
130130

131131
```js
132132
function Comment(props) {
@@ -152,13 +152,13 @@ function Comment(props) {
152152
}
153153
```
154154

155-
[](codepen://components-and-props/extracting-components)
155+
[Спробуйте на CodePen](codepen://components-and-props/extracting-components)
156156

157-
It accepts `author` (an object), `text` (a string), and `date` (a date) as props, and describes a comment on a social media website.
157+
Він приймає `author` (об'єкт), `text` (рядок) і `date` (дату) як пропси і представляє собою коментар в соціальній мережі.
158158

159-
This component can be tricky to change because of all the nesting, and it is also hard to reuse individual parts of it. Let's extract a few components from it.
159+
З цим компонентом можуть виникнути складнощі у випадку зміни вкладених елементів. Також важко повторно використовувати окремі його частини. Давайте виокремимо з нього кілька компонентів.
160160

161-
First, we will extract `Avatar`:
161+
По-перше, створимо компонент `Avatar`:
162162

163163
```js{3-6}
164164
function Avatar(props) {
@@ -171,11 +171,11 @@ function Avatar(props) {
171171
}
172172
```
173173

174-
The `Avatar` doesn't need to know that it is being rendered inside a `Comment`. This is why we have given its prop a more generic name: `user` rather than `author`.
174+
Компонент `Avatar` не повинен знати, що він рендериться всередині компонента `Comment`. Ось чому ми дали нашому пропсу більш загальну назву: `user`, а не `author`.
175175

176-
We recommend naming props from the component's own point of view rather than the context in which it is being used.
176+
Ми рекомендуємо називати пропси з точки зору компонента, а не з контексту, в якому вони використовуються.
177177

178-
We can now simplify `Comment` a tiny bit:
178+
Тепер ми можемо спростити і зменшити `Comment`:
179179

180180
```js{5}
181181
function Comment(props) {
@@ -198,7 +198,7 @@ function Comment(props) {
198198
}
199199
```
200200

201-
Next, we will extract a `UserInfo` component that renders an `Avatar` next to the user's name:
201+
Далі ми виокремимо компонент `UserInfo`, який відрендерить `Avatar` поруч з ім'ям користувача:
202202

203203
```js{3-8}
204204
function UserInfo(props) {
@@ -213,7 +213,7 @@ function UserInfo(props) {
213213
}
214214
```
215215

216-
This lets us simplify `Comment` even further:
216+
Це дозволить нам ще більше спростити `Comment`:
217217

218218
```js{4}
219219
function Comment(props) {
@@ -231,32 +231,32 @@ function Comment(props) {
231231
}
232232
```
233233

234-
[](codepen://components-and-props/extracting-components-continued)
234+
[Спробуйте на CodePen](codepen://components-and-props/extracting-components-continued)
235235

236-
Extracting components might seem like grunt work at first, but having a palette of reusable components pays off in larger apps. A good rule of thumb is that if a part of your UI is used several times (`Button`, `Panel`, `Avatar`), or is complex enough on its own (`App`, `FeedStory`, `Comment`), it is a good candidate to be a reusable component.
236+
Розбиття компонентів може здатися спочатку невдячною роботою. Проте, у великих додатках така велика кількість багаторазових компонентів є дуже корисною. Суть в тому, що якщо частина вашого інтерфейсу використовується кілька разів (`Button`,`Panel`, `Avatar`), або сама собою досить складна (`App`, `FeedStory`,`Comment`), краще винести її в окремий компонент.
237237

238-
## Props are Read-Only {#props-are-read-only}
238+
## Пропси можна тільки читати {#props-are-read-only}
239239

240-
Whether you declare a component [as a function or a class](#function-and-class-components), it must never modify its own props. Consider this `sum` function:
240+
Незалежно від того як ви оголосите компонент [як функцію чи клас](#function-and-class-components), він ніколи не повинен змінювати свої власні пропси. Розглянемо функцію `sum`:
241241

242242
```js
243243
function sum(a, b) {
244244
return a + b;
245245
}
246246
```
247247

248-
Such functions are called ["pure"](https://en.wikipedia.org/wiki/Pure_function) because they do not attempt to change their inputs, and always return the same result for the same inputs.
248+
Такі функції називаються ["чистими"](https://en.wikipedia.org/wiki/Pure_function), оскільки вони не намагаються змінити свої аргументи і завжди повертають один і той же результат для тих же аргументів.
249249

250-
In contrast, this function is impure because it changes its own input:
250+
Для порівняння, наступна функція нечиста, оскільки вона змінює свої власні аргументи:
251251

252252
```js
253253
function withdraw(account, amount) {
254254
account.total -= amount;
255255
}
256256
```
257257

258-
React is pretty flexible but it has a single strict rule:
258+
React досить гнучкий, але має одне суворе правило:
259259

260-
**All React components must act like pure functions with respect to their props.**
260+
**Всі React-компоненти повинні працювати як чисті функції відносно їхніх пропсів.**
261261

262-
Of course, application UIs are dynamic and change over time. In the [next section](/docs/state-and-lifecycle.html), we will introduce a new concept of "state". State allows React components to change their output over time in response to user actions, network responses, and anything else, without violating this rule.
262+
Звичайно, інтерфейси користувачів в додатках динамічні і змінюються з часом. У [наступному розділі](/docs/state-and-lifecycle.html) ми представимо нову концепцію "станів". Стан дозволяє React-компонентам змінювати їхній вивід кожного разу у відповідь на дії користувача, відповіді мережі та всього іншого, не порушуючи цього правила.

content/docs/nav.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- id: rendering-elements
1919
title: Rendering Elements
2020
- id: components-and-props
21-
title: Components and Props
21+
title: Компоненти і пропси
2222
- id: state-and-lifecycle
2323
title: State and Lifecycle
2424
- id: handling-events

0 commit comments

Comments
 (0)