diff --git a/content/docs/composition-vs-inheritance.md b/content/docs/composition-vs-inheritance.md index c86735ef7..1d54083ef 100644 --- a/content/docs/composition-vs-inheritance.md +++ b/content/docs/composition-vs-inheritance.md @@ -1,6 +1,6 @@ --- id: composition-vs-inheritance -title: Composition vs Inheritance +title: Композиція проти наслідування permalink: docs/composition-vs-inheritance.html redirect_from: - "docs/multiple-components.html" @@ -8,15 +8,15 @@ prev: lifting-state-up.html next: thinking-in-react.html --- -React has a powerful composition model, and we recommend using composition instead of inheritance to reuse code between components. +React має потужну модель композиції і ми рекомендуємо використовувати композицію замість наслідування для повторного використання коду між компонентами. -In this section, we will consider a few problems where developers new to React often reach for inheritance, and show how we can solve them with composition. +В цьому розділі ми розглянемо кілька проблем, котрі нові React-розробники вирішують за допомогою наслідування і покажемо, як вони вирішуються за допомогою композиції. -## Containment {#containment} +## Запобіжні заходи {#containment} -Some components don't know their children ahead of time. This is especially common for components like `Sidebar` or `Dialog` that represent generic "boxes". +Деякі компоненти не знають заздалегідь про свої дочірні елементи. Це особливо характерно для таких компонентів як `Sidebar` чи `Dialog`, котрі представляють собою загальні контейнери. -We recommend that such components use the special `children` prop to pass children elements directly into their output: +Ми рекомендуємо, щоб такі компоненти використовували особливий проп `children` для передачі дочірніх елементів напряму до свого виводу: ```js{4} function FancyBorder(props) { @@ -28,7 +28,7 @@ function FancyBorder(props) { } ``` -This lets other components pass arbitrary children to them by nesting the JSX: +Це дозволяє іншим компонентам передавати їм довільні дочірні елементи шляхом вкладення JSX: ```js{4-9} function WelcomeDialog() { @@ -38,18 +38,18 @@ function WelcomeDialog() { Welcome
- Thank you for visiting our spacecraft! + Дякуємо, що завітали на борт нашого космічного корабля!
); } ``` -**[Try it on CodePen](https://codepen.io/gaearon/pen/ozqNOV?editors=0010)** +**[Спробувати на CodePen](https://codepen.io/gaearon/pen/ozqNOV?editors=0010)** -Anything inside the `