|
1 | 1 | ---
|
2 | 2 | id: forwarding-refs
|
3 |
| -title: Forwarding Refs |
| 3 | +title: Ref'leri Yönlendirme |
4 | 4 | permalink: docs/forwarding-refs.html
|
5 | 5 | ---
|
6 | 6 |
|
7 |
| -Ref forwarding is a technique for automatically passing a [ref](/docs/refs-and-the-dom.html) through a component to one of its children. This is typically not necessary for most components in the application. However, it can be useful for some kinds of components, especially in reusable component libraries. The most common scenarios are described below. |
| 7 | +Ref yönlendirme bir [ref](/docs/refs-and-the-dom.html)'i üst bileşenlerden alt bileşenlerin birine otomatik olarak aktarma tekniğidir. Bu genellikle uygulamadaki çoğu bileşen için gerekli değildir. Ama bazı bileşen türleri için faydalı olabilir, özellikle yeniden kullanılabilir bileşen kütüphaneleri için. En yaygın senaryolar aşağıda açıklanmaktadır. |
8 | 8 |
|
9 |
| -## Forwarding refs to DOM components {#forwarding-refs-to-dom-components} |
| 9 | +## Ref'leri DOM bileşenlerine aktarmak {#forwarding-refs-to-dom-components} |
10 | 10 |
|
11 |
| -Consider a `FancyButton` component that renders the native `button` DOM element: |
| 11 | +Yerel (native) `button` öğesini oluşturan `FancyButton` bileşenini düşünün: |
12 | 12 | `embed:forwarding-refs/fancy-button-simple.js`
|
13 | 13 |
|
14 |
| -React components hide their implementation details, including their rendered output. Other components using `FancyButton` **usually will not need to** [obtain a ref](/docs/refs-and-the-dom.html) to the inner `button` DOM element. This is good because it prevents components from relying on each other's DOM structure too much. |
| 14 | +React bileşenleri, render edilen çıktıları da dahil olacak bir şekilde uygulama ayrıntılarını gizler. `FancyButton` bileşenini kullanan diğer bileşenler, alt `button` DOM elemanı için genellikle **gerekmeyen** [ref elde ederler.](/docs/refs-and-the-dom.html). Bu iyi bir şeydir, çünkü bileşenlerin birbirilerinin DOM yapısına fazla bağımlı olmasını önler. |
15 | 15 |
|
16 |
| -Although such encapsulation is desirable for application-level components like `FeedStory` or `Comment`, it can be inconvenient for highly reusable "leaf" components like `FancyButton` or `MyTextInput`. These components tend to be used throughout the application in a similar manner as a regular DOM `button` and `input`, and accessing their DOM nodes may be unavoidable for managing focus, selection, or animations. |
| 16 | +Her ne kadar bu kapsülleme (encapsulation) `FeedStory` veya `Comment` gibi uygulama seviyesi bileşenler için arzu edilse de, `FancyButton` veya `MyTextInput` gibi yüksek oranda yeniden kullanılabilir "yaprak" bileşenler için sakıncalı olabilir. Bu bileşenler uygulama boyunca normal bir DOM `button` ve `input` öğeleri gibi benzer şekilde kullanılma eğilimindedir, odaklama, seçim veya animasyonları yönetmek için DOM düğümlerine erişmek kaçınılmaz olabilir. |
17 | 17 |
|
18 |
| -**Ref forwarding is an opt-in feature that lets some components take a `ref` they receive, and pass it further down (in other words, "forward" it) to a child.** |
| 18 | +**Ref yönlendirme, bazı bileşenlerin aldıkları bir ref'i almasını ve daha alt elemene aktarmasını sağlayan bir etkinleştirme özelliğidir** |
19 | 19 |
|
20 |
| -In the example below, `FancyButton` uses `React.forwardRef` to obtain the `ref` passed to it, and then forward it to the DOM `button` that it renders: |
| 20 | +Alttaki örnekte, `FancyButton` kendisine aktarılan ref'i elde etmek için `React.forwardRef` kullanılır ve ardından oluşturduğu DOM `button`'a iletir: |
21 | 21 |
|
22 | 22 | `embed:forwarding-refs/fancy-button-simple-ref.js`
|
23 | 23 |
|
24 |
| -This way, components using `FancyButton` can get a ref to the underlying `button` DOM node and access it if necessary—just like if they used a DOM `button` directly. |
| 24 | +Bu şekilde, `FancyButton` kullanan bileşenler, temelde bulunan `button` DOM düğümüne bir ref oluşturabilir ve gerekirse doğrudan bir DOM `button` kullanmış gibi erişebilir. |
25 | 25 |
|
26 |
| -Here is a step-by-step explanation of what happens in the above example: |
| 26 | +Yukarıdaki örnekte neler olduğuna dair adım adım açıklama: |
27 | 27 |
|
28 |
| -1. We create a [React ref](/docs/refs-and-the-dom.html) by calling `React.createRef` and assign it to a `ref` variable. |
29 |
| -1. We pass our `ref` down to `<FancyButton ref={ref}>` by specifying it as a JSX attribute. |
30 |
| -1. React passes the `ref` to the `(props, ref) => ...` function inside `forwardRef` as a second argument. |
31 |
| -1. We forward this `ref` argument down to `<button ref={ref}>` by specifying it as a JSX attribute. |
32 |
| -1. When the ref is attached, `ref.current` will point to the `<button>` DOM node. |
| 28 | +1. `React.createRef`'i çağırarak bir [React ref](/docs/refs-and-the-dom.html) oluşturuyoruz ve `ref` değişkenine atama yapıyoruz. |
| 29 | +1. JSX özelliği olarak belirterek `ref`'i `<FancyButton ref={ref}>` bileşenine aktarıyoruz. |
| 30 | +1. React, ikinci bir argüman olarak `ref`'yi `forwardRef` içindeki `(props, ref) => ...` fonksiyonuna iletir. |
| 31 | +1. JSX özelliği olarak belirterek, `ref` argümanını `<button ref={ref}>`'a aktarıyoruz. |
| 32 | +1. Ref eklendiğinde. `ref.current`, `<button>` DOM düğmüne işaret edecektir. |
33 | 33 |
|
34 |
| ->Note |
| 34 | +>Not |
35 | 35 | >
|
36 |
| ->The second `ref` argument only exists when you define a component with `React.forwardRef` call. Regular function or class components don't receive the `ref` argument, and ref is not available in props either. |
| 36 | +>İkinci `ref` argümanı yalnızca `React.forwardRef` çağrısıyla oluşur. Normal fonksiyon veya sınıf bileşenleri `ref` argümanı almaz, ayrıca ref prop'larda da mevcut değildir. |
37 | 37 | >
|
38 |
| ->Ref forwarding is not limited to DOM components. You can forward refs to class component instances, too. |
| 38 | +>Ref yönlendirme yalnızca DOM bileşenleri ile sınırlı değildir. ref'leri sınıf bileşenlerinden türetilen nesnelere de aktarabilirsiniz. |
39 | 39 |
|
40 |
| -## Note for component library maintainers {#note-for-component-library-maintainers} |
| 40 | +## Bileşen kütüphanesine bakım yapanlara not {#note-for-component-library-maintainers} |
41 | 41 |
|
42 |
| -**When you start using `forwardRef` in a component library, you should treat it as a breaking change and release a new major version of your library.** This is because your library likely has an observably different behavior (such as what refs get assigned to, and what types are exported), and this can break apps and other libraries that depend on the old behavior. |
| 42 | +**`forwardRef`'i bir bileşen içinde kullanmaya başladığınızda, Bunu tehlikeli bir değişim olarak değerlendirmelisiniz ve yeni bir sürüm yayınlamalısınız.** Bunun nedeni, kütüphanenizin büyük olasılıkla gözle görülür şekilde farklı bir yaklaşıma sahip olmasıdır (ref'lerin ataması ve hangi türlerin dışa aktarıldığı gibi), ve eski yaklaşıma bağlı uygulamaları ve diğer kütüphaneleri etkiliyebilir. |
43 | 43 |
|
44 |
| -Conditionally applying `React.forwardRef` when it exists is also not recommended for the same reasons: it changes how your library behaves and can break your users' apps when they upgrade React itself. |
| 44 | +Mevcut olduğunda `React.forwardRef`'i koşullu olarak uygulamak da aynı nedenlerle önerilmez: |
| 45 | +Kütüphanenizin biçimini değiştirir ve React'i yükselttiklerinde kullanıcılarınızın uygulamalarını bozabilir. |
45 | 46 |
|
46 |
| -## Forwarding refs in higher-order components {#forwarding-refs-in-higher-order-components} |
| 47 | +## Üst-Seviye Bileşenlerde ref'leri yönlendirme {#forwarding-refs-in-higher-order-components} |
47 | 48 |
|
48 |
| -This technique can also be particularly useful with [higher-order components](/docs/higher-order-components.html) (also known as HOCs). Let's start with an example HOC that logs component props to the console: |
| 49 | +Bu teknik, üst-seviye bileşenlerde özellikle yararlı olabilir [higher-order components](/docs/higher-order-components.html) (HOC olarak da bilinir). Konsola bileşen prop'larını yazdıran örnek bir HOC ile başlayalım: |
49 | 50 | `embed:forwarding-refs/log-props-before.js`
|
50 | 51 |
|
51 |
| -The "logProps" HOC passes all `props` through to the component it wraps, so the rendered output will be the same. For example, we can use this HOC to log all props that get passed to our "fancy button" component: |
| 52 | +"logProps" HOC, tüm prop'ları kapladığı bileşene aktarır, böylece sonuç aynı olacaktır. |
| 53 | +Örneğin, "fancy button" bileşenimize iletilen tüm prop'ları yazdırmak için bu HOC'u kullanabiliriz. |
52 | 54 | `embed:forwarding-refs/fancy-button.js`
|
53 | 55 |
|
54 |
| -There is one caveat to the above example: refs will not get passed through. That's because `ref` is not a prop. Like `key`, it's handled differently by React. If you add a ref to a HOC, the ref will refer to the outermost container component, not the wrapped component. |
| 56 | +Yukarıdaki örnekle ilgili bir uyarı: ref'ler iletilmeyecek. Bunun nedeni `ref` prop değildir. `key` gibi, React tarafından farklı şekilde ele alınır. Bir HOC'a ref eklerseniz ref, kaplanmış bileşene değil, en dıştaki kapsaycı bileşene atıfta bulunacaktır. |
55 | 57 |
|
56 |
| -This means that refs intended for our `FancyButton` component will actually be attached to the `LogProps` component: |
| 58 | +Bu, `FancyButton` bileşeni için istenilen ref'lerin aslında `LogProps` bileşenine ekleneceği anlamına gelir. |
57 | 59 | `embed:forwarding-refs/fancy-button-ref.js`
|
58 | 60 |
|
59 |
| -Fortunately, we can explicitly forward refs to the inner `FancyButton` component using the `React.forwardRef` API. `React.forwardRef` accepts a render function that receives `props` and `ref` parameters and returns a React node. For example: |
| 61 | +Neyse ki, ref'leri `React.forwardRef` API'ını kullanarak iç `FancyButton` bileşenine iletebiliriz. `React.forwardRef`, `props` ve `ref` parametrelerini alan ve bir React düğüm'u döndüren render fonksiyonu kabul eder. Örneğin: |
60 | 62 | `embed:forwarding-refs/log-props-after.js`
|
61 | 63 |
|
62 | 64 | ## Displaying a custom name in DevTools {#displaying-a-custom-name-in-devtools}
|
63 | 65 |
|
64 |
| -`React.forwardRef` accepts a render function. React DevTools uses this function to determine what to display for the ref forwarding component. |
| 66 | +`React.forwardRef` render fonksiyonu kabul eder. React DevTools, ref yönlendirme bileşeni için neyin görüntüleneceğini belirlemek için bu fonksiyonu kullanır. |
65 | 67 |
|
66 |
| -For example, the following component will appear as "*ForwardRef*" in the DevTools: |
| 68 | +Örneğin, aşağıdaki bileşen DevTools'ta "*ForwardRef*" olarak görünür |
67 | 69 |
|
68 | 70 | `embed:forwarding-refs/wrapped-component.js`
|
69 | 71 |
|
70 |
| -If you name the render function, DevTools will also include its name (e.g. "*ForwardRef(myFunction)*"): |
| 72 | +Oluşturma fonksiyonunu adlandırırsanız, DevTools ayrıca adını da ekler (örn. "*ForwardRef(myFunction)*"): |
71 | 73 |
|
72 | 74 | `embed:forwarding-refs/wrapped-component-with-function-name.js`
|
73 | 75 |
|
74 |
| -You can even set the function's `displayName` property to include the component you're wrapping: |
| 76 | +Hatta fonksiyonun `displayName` özelliğini kapladığınız bileşeni içerecek şekilde ayarlayabilirsiniz: |
75 | 77 |
|
76 | 78 | `embed:forwarding-refs/customized-display-name.js`
|
0 commit comments