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: content/docs/components-and-props.md
+51-45Lines changed: 51 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
id: components-and-props
3
-
title: Components and Props
3
+
title: Bileşenler ve Prop'lar
4
4
permalink: docs/components-and-props.html
5
5
redirect_from:
6
6
- "docs/reusable-components.html"
@@ -16,23 +16,25 @@ prev: rendering-elements.html
16
16
next: state-and-lifecycle.html
17
17
---
18
18
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
+
Bileşenler, kullanıcı arayüzünü ayrıştırarak birbirinden bağımsız ve tekrar kullanılabilen parçalar oluşturmanızı sağlar. Bu sayede her bir parçayı birbirinden izole bir şekilde düşünerek kodlayabilirsiniz.
20
20
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
+
Bu sayfa, bileşenlerin ne olduğuna dair bir fikir edinmenizi sağlayacaktır. [Bileşenler API dokümanını](/docs/react-component.html) inceleyerek daha detaylı bilgi edinebilirsiniz.
22
22
23
-
## Function and Class Components {#function-and-class-components}
23
+
Kavramsal olarak bileşenler, JavaScript fonksiyonları gibidir. Bileşenler, "props" adındaki girdileri opsiyonel olarak alırlar ve ekranda görüntülenecek React elementlerini geri döndürürler.
24
24
25
-
The simplest way to define a component is to write a JavaScript function:
25
+
## Fonksiyon ve Sınıf Bileşenleri {#function-and-class-components}
26
+
27
+
Bir bileşen oluşturmak için en basit yol, bir JavaScript fonksiyonu yazmaktır:
26
28
27
29
```js
28
30
functionWelcome(props) {
29
31
return<h1>Hello, {props.name}</h1>;
30
32
}
31
33
```
32
34
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.
35
+
Bu fonksiyon, girdi olarak "props" (properties) adındaki tek bir nesneyi aldığı ve geriye bir React elementi döndürdüğü için geçerli bir React bileşenidir. Bu tarz bileşenler, gerçekten de birer JavaScript fonksiyonları oldukları için adına "fonksiyonel bileşenler" denir.
34
36
35
-
You can also use an [ES6 class](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes)to define a component:
37
+
Fonksiyon yerine, bir [ES6 sınıfı](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes)kullanarak da React bileşeni oluşturabilirsiniz:
36
38
37
39
```js
38
40
classWelcomeextendsReact.Component {
@@ -42,27 +44,27 @@ class Welcome extends React.Component {
42
44
}
43
45
```
44
46
45
-
The above two components are equivalent from React's point of view.
47
+
Üstteki her iki bileşen de React'in bakış açısından birbirine eşittirler.
46
48
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.
49
+
Sınıf bileşenleri, fonksiyon bileşenlerine göre bazı ek özelliklere sahiptirler. Buna [sonraki bölümlerde](/docs/state-and-lifecycle.html) değineceğiz. Fakat şimdilik, kısa olması açısından fonksiyon bileşenleri kullanacağız.
48
50
49
-
## Rendering a Component {#rendering-a-component}
51
+
## Bir Bileşenin Render Edilmesi {#rendering-a-component}
50
52
51
-
Previously, we only encountered React elements that represent DOM tags:
53
+
Önceki bölümlerde, React elementi olarak sadece DOM elementlerini ele almıştık.
52
54
53
55
```js
54
56
constelement=<div />;
55
57
```
56
58
57
-
However, elements can also represent user-defined components:
59
+
Ancak elementler, kullanıcı tanımlı bileşenler de olabilirler:
58
60
59
61
```js
60
62
constelement=<Welcome name="Sara"/>;
61
63
```
62
64
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".
65
+
React, kullanıcı tanımlı bir bileşeni gördüğü zaman, bünyesinde yer alan JSX özelliklerini bu bileşene tek bir nesne olarak aktarır. Bu nesneye "props" adı verilir.
64
66
65
-
For example, this code renders "Hello, Sara" on the page:
67
+
Örneğin aşağıdaki kod, sayfada "Hello, Sara" mesajını görüntüler:
Bu örnekte, hangi olayların gerçekleştiğine bir bakalım:
82
84
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>`.
85
+
1.`<Welcome name="Sara" />`elementi ile birlikte `ReactDOM.render()` fonksiyonunu çağırıyoruz.
86
+
2.Devamında React, `{name: 'Sara'}`prop'u ile `Welcome` bileşenini çağırıyor.
87
+
3.`Welcome`bileşenimiz, sonuç olarak geriye bir `<h1>Hello, Sara</h1>`elementi döndürüyor.
88
+
4. React DOM, `<h1>Hello, Sara</h1>` ile eşleşmek için, DOM'u arka planda efektif bir şekilde güncelliyor .
87
89
88
-
>**Note:**Always start component names with a capital letter.
90
+
>**Not:**Bileşen isimlendirmelerinde daima büyük harfle başlayınız.
89
91
>
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.
92
+
>Çünkü React, küçük harfle başlayan bileşenlere DOM etiketleri gibi davranır. Örneğin `<div />`, bir HTML div etiketini temsil eder, fakat`<Welcome />`ise bir bileşeni temsil eder ve kodun etki alanında `Welcome`'ın tanımlı olmasını gerektirir.
91
93
>
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).
94
+
>Bu isimlendirmenin nedeni hakkında detaylı bilgi edinmek için lütfen [Derinlemesine JSX](/docs/jsx-in-depth.html#user-defined-components-must-be-capitalized) sayfasına bakınız.
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.
98
+
Bileşenler, çıktılarında diğer bileşenleri gösterebilir. Bu sayede soyutlanan bir bileşen, herhangi bir ayrıntı düzeyinde tekrar kullanılabilir. Butonlar, formlar, diyaloglar, ekranlar ve daha nicesi React uygulamalarında yaygın bir şekilde bileşen olarak ifade edilebilirler.
97
99
98
-
For example, we can create an `App` component that renders `Welcome` many times:
100
+
Örneğin, `Welcome`'ı istediğimiz kadar görüntüleyecek bir `App` bileşeni oluşturabiliriz:
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.
125
+
Genellikle, yeni React uygulamaları, en üstte bir tane `App`bileşeni içerirler. Ancak React'i mevcut uygulamanıza entegre ediyorsanız, `Button`gibi en küçük bileşenlerden başlayacak şekilde basitten karmaşığa doğru ilerleyerek bileşen hiyerarşisini oluşturabilirsiniz.
It accepts`author`(an object), `text`(a string), and `date`(a date) as props, and describes a comment on a social media website.
159
+
Üstteki bileşen;`author`nesnesini, `text`metnini, ve bir `date`tarihini prop olarak alır. Bu bileşen, bir sosyal medya sitesinde yorum kutucuğunun görüntülenmesini sağlar.
158
160
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.
161
+
İç içe halde bulunan bu bileşenin üzerinde değişiklik yapmak zor olabilir. Ayrıca bünyesindeki DOM elementlerinin de tekrar kullanılabilirliği oldukça düşük seviyede. Bu durumu çözmek için, kod içerisinden birkaç bileşen çıkarabiliriz.
160
162
161
-
First, we will extract `Avatar`:
163
+
Öncelikle `Avatar` bileşenini çıkaralım:
162
164
163
165
```js{3-6}
164
166
function Avatar(props) {
@@ -171,11 +173,11 @@ function Avatar(props) {
171
173
}
172
174
```
173
175
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`.
176
+
`Avatar`bileşeninin, bir `Comment` bileşeni içerisinde render edildiğini bilmesi gerekli değildir. Bu nedenle `Avatar` bileşenini, gelecekte uygulamanın daha farklı yerlerinde de kullanma ihtimalimiz bulunduğundan dolayı, prop değişkenleri için `author` yerine`user`gibi daha genel bir isim verebiliriz.
175
177
176
-
We recommend naming props from the component's own point of view rather than the context in which it is being used.
178
+
Prop'lar isimlendirilirken, ilgili bileşenin hangi bileşen içerisinde kullanıldığını ele almak yerine, bileşeni bağımsız olarak ele almanız gerekmektedir.
177
179
178
-
We can now simplify `Comment`a tiny bit:
180
+
Yaptığımız değişiklikle `Comment`bileşenini az bir miktar basitleştirmiş olduk:
179
181
180
182
```js{5}
181
183
function Comment(props) {
@@ -198,7 +200,7 @@ function Comment(props) {
198
200
}
199
201
```
200
202
201
-
Next, we will extract a `UserInfo` component that renders an `Avatar` next to the user's name:
203
+
Şimdi `Avatar` ile birlikte, kullanıcı adını da render edecek olan `UserInfo` bileşenini kod içerisinden çıkarabiliriz.
202
204
203
205
```js{3-8}
204
206
function UserInfo(props) {
@@ -213,7 +215,7 @@ function UserInfo(props) {
213
215
}
214
216
```
215
217
216
-
This lets us simplify `Comment`even further:
218
+
Bu sayede `Comment`bileşeni daha da basitleşmiş hale geldi:
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.
238
+
Bileşenlerin çıkarılması en başta angarya bir işlem gibi görünebilir. Fakat büyük çaplı uygulamalarda, tekrar kullanılabilir bileşenler içeren bir **bileşen paletine** sahip olmak oldukça faydalı hale gelecektir. Bileşen çıkarmanın genel mantığı aşağıdaki gibidir:
239
+
* Eğer kullanıcı arayüzündeki bir eleman (`Button`, `Panel`, `Avatar`) uygulama içerisinde birçok defa kullanılıyorsa,
240
+
* Eğer bir bileşen (`App`, `FeedStory`, `Comment`) oldukça karmaşık hale geldiyse,
241
+
242
+
bu bileşen, içerisinden bileşenler çıkarmak için iyi bir adaydır diyebiliriz.
237
243
238
-
## Props are Read-Only {#props-are-read-only}
244
+
## Prop'lar ve Salt Okunurlar {#props-are-read-only}
239
245
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:
246
+
[Fonksiyon veya sınıf](#function-and-class-components) bileşeninden herhangi birini oluşturduğunuzda, bu bileşen kendi prop'larını asla değiştirmemelidir. Örneğin aşağıdaki`sum`fonksiyonunu ele alalım:
241
247
242
248
```js
243
249
functionsum(a, b) {
244
250
return a + b;
245
251
}
246
252
```
247
253
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.
254
+
Bu tarz fonksiyonlar, kendi girdi parametrelerini değiştirmedikleri ve her zaman aynı parametreler için aynı sonucu ürettiklerinden dolayı ["pure"](https://en.wikipedia.org/wiki/Pure_function)(saf) fonksiyonlardır.
249
255
250
-
In contrast, this function is impure because it changes its own input:
256
+
Tam ters örnek verecek olursak, aşağıdaki fonksiyon impure'dür (saf değildir). Çünkü kendi girdi değerini değiştirmektedir:
251
257
252
258
```js
253
259
functionwithdraw(account, amount) {
254
260
account.total-= amount;
255
261
}
256
262
```
257
263
258
-
React is pretty flexible but it has a single strict rule:
264
+
React, kod yazımında oldukça esnek olmasına rağmen, sadece bir tek kuralı şart koşmaktadır:
259
265
260
-
**All React components must act like pure functions with respect to their props.**
266
+
**Bütün React bileşenleri pure fonksiyonlar gibi davranmalı, ve prop'larını asla değiştirmemelidirler.**
261
267
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.
268
+
Tabi ki kullanıcı arayüzleri dinamiktir ve zaman içerisinde değişiklik gösterir. [Sonraki bölümde](/docs/state-and-lifecycle.html), "state" (durum) adındaki yeni konsepte değineceğiz. State bu kurala sadık kalarak; kullanıcı etkileşimleri, ağ istekleri ve diğer şeylerden dolayı zaman içerisinde değişen arayüzün görüntülenmesi için, React bileşenlerinin kendi çıktılarını değiştirebilmesine izin verir.
0 commit comments