Skip to content

Commit 3841db7

Browse files
authored
Merge pull request #496 from enesthedev/find-dom-node
translate `findDOMNode`
2 parents e59728f + 3b19ceb commit 3841db7

File tree

1 file changed

+68
-49
lines changed

1 file changed

+68
-49
lines changed

src/content/reference/react-dom/findDOMNode.md

Lines changed: 68 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ title: findDOMNode
44

55
<Deprecated>
66

7-
This API will be removed in a future major version of React. [See the alternatives.](#alternatives)
7+
Bu API, React'in gelecekteki bir ana sürümünde kaldırılacaktır. [Alternatif API'ları görüntüle.](#alternatives)
88

99
</Deprecated>
1010

1111
<Intro>
1212

13-
`findDOMNode` finds the browser DOM node for a React [class component](/reference/react/Component) instance.
13+
`findDOMNode`, bir [sınıf bileşeni](/reference/react/Component) nesnesine ait tarayıcı DOM düğümünü döndürür.
1414

1515
```js
1616
const domNode = findDOMNode(componentInstance)
@@ -22,46 +22,47 @@ const domNode = findDOMNode(componentInstance)
2222

2323
---
2424

25-
## Reference {/*reference*/}
25+
## Referans {/*reference*/}
2626

2727
### `findDOMNode(componentInstance)` {/*finddomnode*/}
2828

29-
Call `findDOMNode` to find the browser DOM node for a given React [class component](/reference/react/Component) instance.
29+
Bir React [sınıf bileşenine](/reference/react/Component) ait DOM düğümünü bulmak için `findDOMNode` fonksiyonunu çağırın.
3030

3131
```js
3232
import { findDOMNode } from 'react-dom';
3333

3434
const domNode = findDOMNode(componentInstance);
3535
```
3636

37-
[See more examples below.](#usage)
37+
[Daha fazla kullanım örneği için buraya tıklayın.](#usage)
3838

39-
#### Parameters {/*parameters*/}
39+
#### Parametreler {/*parameters*/}
4040

41-
* `componentInstance`: An instance of the [`Component`](/reference/react/Component) subclass. For example, `this` inside a class component.
41+
* `componentInstance`: [`Bileşene`](/reference/react/Component) ait nesneyi ifade eder. Örnekle, React sınıf bileşeni içerisinde kullanılan `this` işaretcisi parametre olarak kullanılabilir.
4242

4343

44-
#### Returns {/*returns*/}
44+
#### Dönüş Değerleri {/*returns*/}
4545

46-
`findDOMNode` returns the first closest browser DOM node within the given `componentInstance`. When a component renders to `null`, or renders `false`, `findDOMNode` returns `null`. When a component renders to a string, `findDOMNode` returns a text DOM node containing that value.
46+
`findDOMNode`, verilen `componentInstance` bileşenini içeren en yakın DOM düğümünü döndürür. Eğer bir bileşen `null` veya `false` olarak render edilirse, `findDOMNode` fonksiyonu `null` değerini döndürür. Eğer bileşen sadece metin içerecek şekilde render edilirse, `findDOMNode`, o değeri içeren bir metin DOM nesnesi döndürür.
4747

48-
#### Caveats {/*caveats*/}
48+
#### Uyarılar {/*caveats*/}
4949

50-
* A component may return an array or a [Fragment](/reference/react/Fragment) with multiple children. In that case `findDOMNode`, will return the DOM node corresponding to the first non-empty child.
50+
* React bileşeni bazı durumlarda bir [Fragment](/reference/react/Fragment) ya da bir dizi içerebilir. Bu durumda `findDOMNode` fonsiyonu içi boş olmayan ilk alt nesneyi döndürecektir.
5151

52-
* `findDOMNode` only works on mounted components (that is, components that have been placed in the DOM). If you try to call this on a component that has not been mounted yet (like calling `findDOMNode()` in `render()` on a component that has yet to be created), an exception will be thrown.
52+
* `findDOMNode` fonksiyonu sadece render edilmiş bileşenlerde çalışır. (Yani, bir bileşenin DOM üzerinde bir yer edinmiş olması gerekir). Eğer render edilmemiş bir bileşen için `findDOMNode` fonksiyonunu çağırmaya çalışırsanız (Örn: `findDOMNode()` fonksiyonunu, henüz oluşturulmamış bir bileşenin `render()` fonksiyonu içerisinde çağırırsanız) uygulama genelinde bir hata fırlatılır ve uygulama çalışmaz.
5353

54-
* `findDOMNode` only returns the result at the time of your call. If a child component renders a different node later, there is no way for you to be notified of this change.
54+
* `findDOMNode` fonksiyonu sadece çağırıldığı andaki sonucu döndürür. Eğer alt bileşen daha sonradan farklı bir node render eder ise bu değişimden haberdar olmak mümkün değildir.
5555

56-
* `findDOMNode` accepts a class component instance, so it can't be used with function components.
56+
* `findDOMNode` sadece React sınıf bileşenleri ile çalışır, React fonksiyon bileşeni yapısı ile kullanılamaz.
5757

5858
---
5959

60-
## Usage {/*usage*/}
60+
## Kullanım {/*usage*/}
6161

62-
### Finding the root DOM node of a class component {/*finding-the-root-dom-node-of-a-class-component*/}
62+
### Sınıf bileşeninin ana DOM objesinin bulunması {/*finding-the-root-dom-node-of-a-class-component*/}
63+
64+
Render edilmiş DOM düğümünü bulabilmek için `findDOMNode` fonksiyonunu bir React sınıf bileşeni içerisinde çağırın. (React sınıf bileşenine `this` niteliğini kullanarak erişebilirsiniz)
6365

64-
Call `findDOMNode` with a [class component](/reference/react/Component) instance (usually, `this`) to find the DOM node it has rendered.
6566

6667
```js {3}
6768
class AutoselectingInput extends Component {
@@ -71,12 +72,20 @@ class AutoselectingInput extends Component {
7172
}
7273

7374
render() {
74-
return <input defaultValue="Hello" />
75+
return <input defaultValue="Merhaba" />
7576
}
7677
}
7778
```
7879

79-
Here, the `input` variable will be set to the `<input>` DOM element. This lets you do something with it. For example, when clicking "Show example" below mounts the input, [`input.select()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select) selects all text in the input:
80+
Yukarıdaki kod parçacığında `ìnput` değişkeni `findDOMNode` fonksiyonu aracılığı ile render metodu içerisindeki `<input>` DOM nesnesine ulaşır.
81+
82+
Şimdi ulaşılan input nesnesiyle bir şeyler yapalım. Bir `show` state'i oluşturalım ve varsayılan değeri `false` olsun. `Göster` buton elementi aracılığı ile state'i güncelleyelim. Güncellenen `show` state'i ile `<AutoSelectingInput />` bileşeni render edilsin.
83+
84+
Alt tarafta gerekli kaynak kodu görüntüleyebilirsiniz, şimdi de neler olduğunu açıklayalım.
85+
86+
`Göster` butonuna tıklandığında `AutoselectingInput` bileşeni render edilir ve tarayıcı ekranında görünür hale gelir. Ardından `findDOMNode` fonksiyonu çağrılarak input nesnesi bulunur.
87+
88+
Bulunan nesnede [`input.select()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select) metodu aracılığı ile içinde yazılı olan `Merhaba` yazısı seçili olarak gösterilir.
8089

8190
<Sandpack>
8291

@@ -89,7 +98,7 @@ export default function App() {
8998
return (
9099
<>
91100
<button onClick={() => setShow(true)}>
92-
Show example
101+
Göster
93102
</button>
94103
<hr />
95104
{show && <AutoselectingInput />}
@@ -109,7 +118,7 @@ class AutoselectingInput extends Component {
109118
}
110119

111120
render() {
112-
return <input defaultValue="Hello" />
121+
return <input defaultValue="Merhaba" />
113122
}
114123
}
115124

@@ -120,11 +129,11 @@ export default AutoselectingInput;
120129

121130
---
122131

123-
## Alternatives {/*alternatives*/}
132+
## Alternatifler {/*alternatives*/}
124133

125-
### Reading component's own DOM node from a ref {/*reading-components-own-dom-node-from-a-ref*/}
134+
### Referans değerinden bileşene ait DOM nesnesine ulaşma {/*reading-components-own-dom-node-from-a-ref*/}
126135

127-
Code using `findDOMNode` is fragile because the connection between the JSX node and the code manipulating the corresponding DOM node is not explicit. For example, try wrapping this `<input />` into a `<div>`:
136+
`findDOMNode` fonksiyonunun kullanıldığı kodlar kırılgan kodlardır. Çünkü JSX nesnesi ile DOM nesnesi arasındaki bağlantı açık bir şekilde ifade edilmemektedir. Örn, kod içerisindeki `<input />` kısmını `<div>` ile sarmayı deneyelim:
128137

129138
<Sandpack>
130139

@@ -137,7 +146,7 @@ export default function App() {
137146
return (
138147
<>
139148
<button onClick={() => setShow(true)}>
140-
Show example
149+
Göster
141150
</button>
142151
<hr />
143152
{show && <AutoselectingInput />}
@@ -156,7 +165,7 @@ class AutoselectingInput extends Component {
156165
input.select()
157166
}
158167
render() {
159-
return <input defaultValue="Hello" />
168+
return <input defaultValue="Merhaba" />
160169
}
161170
}
162171

@@ -165,9 +174,15 @@ export default AutoselectingInput;
165174

166175
</Sandpack>
167176

168-
This will break the code because now, `findDOMNode(this)` finds the `<div>` DOM node, but the code expects an `<input>` DOM node. To avoid these kinds of problems, use [`createRef`](/reference/react/createRef) to manage a specific DOM node.
177+
Bu kullanım kodun çalışmasına engel olacaktır. Çünkü `findDOMNode` geriye `<div>` DOM düğümünü döndürecektir fakat kod dönüş değerinin `<input />` DOM nesnesi olmasını bekler.
178+
179+
Bu tür problemlerin önüne geçmek spesifik bir DOM nesnesi seçebilen için [`createRef`](/reference/react/createRef) fonksiyonunu kullanın.
169180

170-
In this example, `findDOMNode` is no longer used. Instead, `inputRef = createRef(null)` is defined as an instance field on the class. To read the DOM node from it, you can use `this.inputRef.current`. To attach it to the JSX, you render `<input ref={this.inputRef} />`. This connects the code using the DOM node to its JSX:
181+
Alt kısımdaki örnekte `findDOMNode` yerine `createRef`'in nasıl kullanıdğını daha iyi anlayabilirsiniz.
182+
183+
Bu örnekte, `ìnputRef = createRef(null)` kodunda `null` değer tanımlamasına sahip yeni bir referans oluşturduk. Oluşturduğumuz bu referansı `ref={this.inputRef}` niteliği aracılığıyla `input` elementine tanımladık.
184+
185+
Bileşen oluşturulduğunda ise `this.inputRef.current` notasyonu ile DOM nesnesine ulaştık ve `input.select()` metodunu yeniden kullanılabilir hale getirdik.
171186

172187
<Sandpack>
173188

@@ -212,7 +227,9 @@ export default AutoselectingInput;
212227

213228
</Sandpack>
214229

215-
In modern React without class components, the equivalent code would call [`useRef`](/reference/react/useRef) instead:
230+
Bahsettiğimiz üzere `findDOMNode` fonksiyon bileşenlerini desteklemiyordu. Referans sisteminde sınırlama olmadan fonksiyon bileşenlerinde de kullanabiliyoruz.
231+
232+
Fonksiyon bileşenlerindeki referans kullanımında `createRef` yerini [`useRef`](/reference/react/useRef) hook'u almakta.
216233

217234
<Sandpack>
218235

@@ -225,7 +242,7 @@ export default function App() {
225242
return (
226243
<>
227244
<button onClick={() => setShow(true)}>
228-
Show example
245+
Göster
229246
</button>
230247
<hr />
231248
{show && <AutoselectingInput />}
@@ -245,19 +262,19 @@ export default function AutoselectingInput() {
245262
input.select();
246263
}, []);
247264

248-
return <input ref={inputRef} defaultValue="Hello" />
265+
return <input ref={inputRef} defaultValue="Merhaba" />
249266
}
250267
```
251268

252269
</Sandpack>
253270

254-
[Read more about manipulating the DOM with refs.](/learn/manipulating-the-dom-with-refs)
271+
[Ref'ler ile DOM manipülasyonu hakkında daha fazla bilgi almak için tıklayın.](/learn/manipulating-the-dom-with-refs)
255272

256273
---
257274

258-
### Reading a child component's DOM node from a forwarded ref {/*reading-a-child-components-dom-node-from-a-forwarded-ref*/}
275+
### Alt bileşene ait DOM nesnesine forwarded ref aracılığı ile ulaşma {/*reading-a-child-components-dom-node-from-a-forwarded-ref*/}
259276

260-
In this example, `findDOMNode(this)` finds a DOM node that belongs to another component. The `AutoselectingInput` renders `MyInput`, which is your own component that renders a browser `<input>`.
277+
Bu örnekte, `findDOMNode(this)` ile başka bir bileşene ait DOM düğümünü bulacağız. `AutoselectingInput` bileşeni, `input` elementinin bulunduğu `MyInput` bileşenini render edecek ve `findDOMNode(this)` fonksiyonunu kullanarak `input` elementine ulaşmaya çalışacağız.
261278

262279
<Sandpack>
263280

@@ -305,14 +322,14 @@ export default function MyInput() {
305322

306323
</Sandpack>
307324

308-
Notice that calling `findDOMNode(this)` inside `AutoselectingInput` still gives you the DOM `<input>`--even though the JSX for this `<input>` is hidden inside the `MyInput` component. This seems convenient for the above example, but it leads to fragile code. Imagine that you wanted to edit `MyInput` later and add a wrapper `<div>` around it. This would break the code of `AutoselectingInput` (which expects to find an `<input>`).
325+
`AutoselectingInput` içindeki `findDOMNode(this)` çağrısının size hala DOM `<input>` verdiğini unutmayın; bu `<input>` için JSX `MyInput` bileşeninin içinde gizli olsa bile. Bu, yukarıdaki örnek için uygun gibi görünse de kodun kırılgan olmasına neden olur. Daha sonra `MyInput`'u düzenlemek ve etrafına bir `<div>` sarmalayıcısı eklemek istediğinizi düşünün. Bu durumda, (bir `<input>` bulmayı bekleyen) `AutoselectingInput` bileşeni doğru çalışmayacaktır.
309326

310-
To replace `findDOMNode` in this example, the two components need to coordinate:
327+
`findDOMNode` yerine ref kullanabilmemiz için iki bileşende de belirli düzenlemeler yapmalıyız.
311328

312-
1. `AutoSelectingInput` should declare a ref, like [in the earlier example](#reading-components-own-dom-node-from-a-ref), and pass it to `<MyInput>`.
313-
2. `MyInput` should be declared with [`forwardRef`](/reference/react/forwardRef) to take that ref and forward it down to the `<input>` node.
329+
1. [Önceki örneklerde](#reading-components-own-dom-node-from-a-ref) işlediğimiz üzere `AutoSelectingInput` içinde bir referans tanımlamalıyız ve bu referansı `MyInput` bileşenine iletmeliyiz.
330+
2. `MyInput` bileşeni ise [`forwardRef`](/reference/react/forwardRef) aracılığı ile bir referans değer döndürmeli ki ortadaki iki referans değeri birbiriyle eşleşsin ve üst bileşen yapısında `input` elementine ait referansı kullanabilelim.
314331

315-
This version does that, so it no longer needs `findDOMNode`:
332+
Nihai versiyonda artık `findDOMNode` kullanmadan başka bir bileşen içindeki DOM nesnesine erişebildik:
316333

317334
<Sandpack>
318335

@@ -325,7 +342,7 @@ export default function App() {
325342
return (
326343
<>
327344
<button onClick={() => setShow(true)}>
328-
Show example
345+
Göster
329346
</button>
330347
<hr />
331348
{show && <AutoselectingInput />}
@@ -360,15 +377,15 @@ export default AutoselectingInput;
360377
import { forwardRef } from 'react';
361378

362379
const MyInput = forwardRef(function MyInput(props, ref) {
363-
return <input ref={ref} defaultValue="Hello" />;
380+
return <input ref={ref} defaultValue="Merhaba" />;
364381
});
365382

366383
export default MyInput;
367384
```
368385

369386
</Sandpack>
370387

371-
Here is how this code would look like with function components instead of classes:
388+
Aşağıdaki örnek bu kodun sınıf bileşeni yerine fonksiyon bileşeninde nasıl kullanılacağını gösteriyor:
372389

373390
<Sandpack>
374391

@@ -381,7 +398,7 @@ export default function App() {
381398
return (
382399
<>
383400
<button onClick={() => setShow(true)}>
384-
Show example
401+
Göster
385402
</button>
386403
<hr />
387404
{show && <AutoselectingInput />}
@@ -402,15 +419,15 @@ export default function AutoselectingInput() {
402419
input.select();
403420
}, []);
404421

405-
return <MyInput ref={inputRef} defaultValue="Hello" />
422+
return <MyInput ref={inputRef} defaultValue="Merhaba" />
406423
}
407424
```
408425

409426
```js MyInput.js
410427
import { forwardRef } from 'react';
411428

412429
const MyInput = forwardRef(function MyInput(props, ref) {
413-
return <input ref={ref} defaultValue="Hello" />;
430+
return <input ref={ref} defaultValue="Merhaba" />;
414431
});
415432

416433
export default MyInput;
@@ -420,16 +437,18 @@ export default MyInput;
420437

421438
---
422439

423-
### Adding a wrapper `<div>` element {/*adding-a-wrapper-div-element*/}
440+
### Kapsayıcı `<div>` elementi ekleme {/*adding-a-wrapper-div-element*/}
441+
442+
Bazen bir bileşenin alt bileşenlerinin konumunu ve boyutunu bilmesi gerekir. Bu durum, `findDOMNode(this)` ile bulunan nesnelerle ve ardından ölçümler için bu nesnelerin [`getBoundingClientRect`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) gibi DOM yöntemleriyle kullanılmasıyla sonuçlanır.
424443

425-
Sometimes a component needs to know the position and size of its children. This makes it tempting to find the children with `findDOMNode(this)`, and then use DOM methods like [`getBoundingClientRect`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) for measurements.
444+
Şu anda bu kullanım için doğrudan bir alternatif yoktur, bu nedenle `findDOMNode` kullanımdan kaldırılmış olsa da henüz React'tan tamamen kaldırılmamıştır.
426445

427-
There is currently no direct equivalent for this use case, which is why `findDOMNode` is deprecated but is not yet removed completely from React. In the meantime, you can try rendering a wrapper `<div>` node around the content as a workaround, and getting a ref to that node. However, extra wrappers can break styling.
446+
Bu durumda çözüm olarak içeriği kapasayacak bir `<div>` elementi oluşturabilirsiniz ve oluşturduğunuz `<div>` elementine bir referans tanımlayabilirsiniz. Ancak unutmamak gerekir ki ekstra oluşturduğunuz kapsayıcılar stil bozulmalarına sebep olabilir.
428447

429448
```js
430449
<div ref={someRef}>
431450
{children}
432451
</div>
433452
```
434453

435-
This also applies to focusing and scrolling to arbitrary children.
454+
Bu aynı zamanda alt bileşenlere `focusing` ve `scrolling` olayları için de geçerlidir.

0 commit comments

Comments
 (0)