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: src/content/learn/reusing-logic-with-custom-hooks.md
+39-39Lines changed: 39 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -264,34 +264,34 @@ function List({ items, shouldSort }) {
264
264
// ...
265
265
}
266
266
```
267
-
// TODO: Continue from here
268
-
You should give `use` prefix to a function (and thus make it a Hook) if it uses at least one Hook inside of it:
267
+
268
+
Bir fonksiyon eğer bir ya da daha fazla Hook'u içeriyorsa, ona `use` ön eki vermelisiniz:
269
269
270
270
```js
271
-
// ✅ Good: A Hook that uses other Hooks
271
+
// ✅ İyi: Diğer Hook'ları kullanan bir Hook
272
272
functionuseAuth() {
273
273
returnuseContext(Auth);
274
274
}
275
275
```
276
276
277
-
Technically, this isn't enforced by React. In principle, you could make a Hook that doesn't call other Hooks. This is often confusing and limiting so it's best to avoid that pattern. However, there may be rare cases where it is helpful. For example, maybe your function doesn't use any Hooks right now, but you plan to add some Hook calls to it in the future. Then it makes sense to name it with the `use` prefix:
277
+
Teknik olarak, bu React tarafından zorunlu kılınmıyor. Prensipte, başka Hook'ları çağırmayan bir Hook yapabilirsiniz. Bu genellikle kafa karıştırıcı ve limitleyicidir, bu yüzden bu örüntüden uzak durmak en iyisidir. Ancak, işe yarayacağı nadir durumlar bulunabilir. Örneğin, belki fonksiyonunu şu anda hiçbir Hook'u kullanmıyor, ancak gelecekte ona bazı Hook çağrıları eklemeyi düşünüyorsunuz. O zaman onu `use` ön eki ile adlandırmak mantıklı olur:
278
278
279
279
```js {3-4}
280
-
// ✅ Good: A Hook that will likely use some other Hooks later
280
+
// ✅ İyi: Gelecekte muhtemelen başka Hook'ları kullanacak bir Hook
281
281
functionuseAuth() {
282
-
// TODO: Replace with this line when authentication is implemented:
282
+
// TODO: Authentication tamamlanınca bu satırı değiştir:
283
283
// return useContext(Auth);
284
284
returnTEST_USER;
285
285
}
286
286
```
287
287
288
-
Then components won't be able to call it conditionally. This will become important when you actually add Hook calls inside. If you don't plan to use Hooks inside it (now or later), don't make it a Hook.
288
+
Bu şekilde bileşenler onu koşullu olarak çağıramayacaktır. Bu, içine Hook çağrıları eklediğinizde önemli olacaktır. Eğer onun içinde Hook kullanmayı (şimdi ya da gelecekte) planlamıyorsanız, onu bir Hook yapmayın.
289
289
290
290
</DeepDive>
291
291
292
-
### Custom Hooks let you share stateful logic, not state itself {/*custom-hooks-let-you-share-stateful-logic-not-state-itself*/}
292
+
### Özel Hook'lar stateli mantığı paylaşmanızı sağlar, state'in kendisini değil {/*custom-hooks-let-you-share-stateful-logic-not-state-itself*/}
293
293
294
-
In the earlier example, when you turned the network on and off, both components updated together. However, it's wrong to think that a single `isOnline` state variable is shared between them. Look at this code:
294
+
Daha önceki bir örnekte, ağı açıp kapattığınızda, her iki bileşen de birlikte güncellendi. Ancak, onların arasında tek bir `isOnline` state değişkeninin paylaşıldığını düşünmek yanlış olur. Bu kodu inceleyin:
295
295
296
296
```js {2,7}
297
297
functionStatusBar() {
@@ -305,7 +305,7 @@ function SaveButton() {
305
305
}
306
306
```
307
307
308
-
It works the same way as before you extracted the duplication:
308
+
Bu, tekrarı çıkartmanızdan önceki hali gibi çalışır:
309
309
310
310
```js {2-5,10-13}
311
311
functionStatusBar() {
@@ -325,9 +325,9 @@ function SaveButton() {
325
325
}
326
326
```
327
327
328
-
These are two completely independent state variables and Effects! They happened to have the same value at the same time because you synchronized them with the same external value (whether the network is on).
328
+
Bunlar tamamen bağımsız iki state değişkenleri ve efektlerdir! Onlar rastlantısal olarak aynı anda aynı değere sahip oldular çünkü onları aynı harici değerle (ağın açık olup olmaması) senkronize ettiniz.
329
329
330
-
To better illustrate this, we'll need a different example. Consider this `Form`component:
330
+
Bunu daha iyi canlandırabilmek adına, farklı bir örnek kullanacağız. Bu `Form`bileşenini ele alın:
331
331
332
332
<Sandpack>
333
333
@@ -349,14 +349,14 @@ export default function Form() {
Notice that it only declares *one* state variable called `value`.
431
+
`value` adında sadece *bir* state değişkeni oluşturduğuna dikkat edin.
432
432
433
-
However, the `Form`component calls `useFormInput`*two times:*
433
+
Yine de, `Form`bileşeni `useFormInput`'u *iki kez* çağırıyor:
434
434
435
435
```js
436
436
functionForm() {
@@ -439,17 +439,17 @@ function Form() {
439
439
// ...
440
440
```
441
441
442
-
This is why it works like declaring two separate state variables!
442
+
Bu yüzden iki ayrı state değişkeni oluşturmuş gibi çalışıyor!
443
443
444
-
**Custom Hooks let you share *stateful logic* but not *state itself.* Each call to a Hook is completely independent from every other call to the same Hook.** This is why the two sandboxes above are completely equivalent. If you'd like, scroll back up and compare them. The behavior before and after extracting a custom Hook is identical.
444
+
**Özel Hook'lar sizin *stateli mantık* paylaşmanıza olanak sağlar, *state'in kendinisi*ni değil. Bir Hook'a yapılan her çağrı aynı Hook'a yapılan tüm çağrılardan bağımsızdır.** Bu nedenle yukarıdaki iki kod alanı tamamen eşdeğerdir. İsterseniz, yukarı kayarak onları karşılaştırın. Özel bir Hook çıkartmadan önceki ve sonraki davranış tamamen aynıdır.
445
445
446
-
When you need to share the state itself between multiple components, [lift it up and pass it down](/learn/sharing-state-between-components) instead.
446
+
State'i birden fazla bileşen arasında paylaşmak istediğinizde, bunun yerine onu [yukarı kaldırın ve aşağı geçirin](/learn/sharing-state-between-components).
447
447
448
-
## Passing reactive values between Hooks {/*passing-reactive-values-between-hooks*/}
448
+
## Hook'lar arasında reaktif değerler geçirme {/*passing-reactive-values-between-hooks*/}
449
449
450
-
The code inside your custom Hooks will re-run during every re-render of your component. This is why, like components, custom Hooks [need to be pure.](/learn/keeping-components-pure) Think of custom Hooks' code as part of your component's body!
450
+
Özel Hook'larınızın içindeki kod, bileşeniniz her yeniden render edildiğinde yeniden yürütülecektir. Bu nedenle, bileşenler gibi, özel Hook'lar da [saf olmalıdır.](/learn/keeping-components-pure) Özel Hook'larınızın kodunu bileşeninizin bir parçası olarak düşünün!
451
451
452
-
Because custom Hooks re-render together with your component, they always receive the latest props and state. To see what this means, consider this chat room example. Change the server URL or the chat room:
452
+
Özel Hook'lar bileşeninizle birlikte yeniden render edildiğinden, her zaman en son prop'ları ve state'i alırlar. Bunun ne anlama geldiğini görmek için, bu sohbet odası örneğini ele alın. Sunucu URL'sini veya sohbet odasını değiştirin:
453
453
454
454
<Sandpack>
455
455
@@ -462,14 +462,14 @@ export default function App() {
0 commit comments