Skip to content

Commit b1f89b0

Browse files
committed
docs: translate custom hooks (10%)
1 parent 7c9c91b commit b1f89b0

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

src/content/learn/reusing-logic-with-custom-hooks.md

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ React, `useState`, `useContext`, ve `useEffect` gibi birkaç yerleşik Hook ile
1919

2020
## Özel Hook'lar: Bileşenler arasında mantığı paylaşma {/*custom-hooks-sharing-logic-between-components*/}
2121

22-
Imagine you're developing an app that heavily relies on the network (as most apps do). You want to warn the user if their network connection has accidentally gone off while they were using your app. How would you go about it? It seems like you'll need two things in your component:
22+
Ağ'a ağır bir şekilde bağlı olan bir uygulama geliştirdiğinizi hayal edin (çoğu uygulamanın bağlı olduğu gibi). Kullanıcıyı, uygulamanızı kullanırken ağ bağlantısının yanlışlıkla kapandığı durumlarda uyarmak istersiniz. Bunu nasıl yapardınız? Bileşeninizde iki şeye ihtiyacınız olduğu gibi görünüyor:
2323

24-
1. A piece of state that tracks whether the network is online.
25-
2. An Effect that subscribes to the global [`online`](https://developer.mozilla.org/en-US/docs/Web/API/Window/online_event) and [`offline`](https://developer.mozilla.org/en-US/docs/Web/API/Window/offline_event) events, and updates that state.
24+
1. Ağınızın çevrimiçi olup olmadığını izleyen bir state parçası.
25+
2. Global [`online`](https://developer.mozilla.org/en-US/docs/Web/API/Window/online_event) ve [`offline`](https://developer.mozilla.org/en-US/docs/Web/API/Window/offline_event) olaylarına abone olan ve bu state'i güncelleyen bir Effect.
2626

27-
This will keep your component [synchronized](/learn/synchronizing-with-effects) with the network status. You might start with something like this:
27+
Bu sizin bileşeninizi ağ durumu ile [senkronize](/learn/synchronizing-with-effects) tutacaktır. Şöyle bir şeyle başlayabilirsiniz:
2828

2929
<Sandpack>
3030

@@ -48,17 +48,17 @@ export default function StatusBar() {
4848
};
4949
}, []);
5050

51-
return <h1>{isOnline ? 'Online' : 'Disconnected'}</h1>;
51+
return <h1>{isOnline ? 'Çevrimiçi' : 'Bağlantı kopmuş'}</h1>;
5252
}
5353
```
5454

5555
</Sandpack>
5656

57-
Try turning your network on and off, and notice how this `StatusBar` updates in response to your actions.
57+
Ağınızı kapatıp açmayı deneyin ve bu `StatusBar`'ın tepki olarak nasıl güncellendiğini fark edin.
5858

59-
Now imagine you *also* want to use the same logic in a different component. You want to implement a Save button that will become disabled and show "Reconnecting..." instead of "Save" while the network is off.
59+
Şimdi *ek olarak* aynı mantığı farklı bir bileşende kullanmak istediğinizi hayal edin. Ağ kapalıyken "Kaydet" yerine "Yeniden bağlanıyor..." yazan ve devre dışı bırakılan bir Kaydet düğmesi uygulamak istiyorsunuz.
6060

61-
To start, you can copy and paste the `isOnline` state and the Effect into `SaveButton`:
61+
Başlangıç olarak, `isOnline` state'ini ve Effect'i `SaveButton`'a kopyalayabilirsiniz:
6262

6363
<Sandpack>
6464

@@ -83,49 +83,49 @@ export default function SaveButton() {
8383
}, []);
8484

8585
function handleSaveClick() {
86-
console.log('Progress saved');
86+
console.log('İlerleme kaydedildi');
8787
}
8888

8989
return (
9090
<button disabled={!isOnline} onClick={handleSaveClick}>
91-
{isOnline ? 'Save progress' : 'Reconnecting...'}
91+
{isOnline ? 'İlerlemeyi kaydet' : 'Yeniden bağlanılıyor...'}
9292
</button>
9393
);
9494
}
9595
```
9696

9797
</Sandpack>
9898

99-
Verify that, if you turn off the network, the button will change its appearance.
99+
Ağı kapatırsanız, düğmenin görünümünün değiştiğini doğrulayın.
100100

101-
These two components work fine, but the duplication in logic between them is unfortunate. It seems like even though they have different *visual appearance,* you want to reuse the logic between them.
101+
Bu iki bileşen iyi çalışıyor, ancak aralarındaki mantık tekrarı talihsiz. Görünen o ki farklı *görsel görünüme* sahip olsalar da, aralarındaki mantığı yeniden kullanmak istiyorsunuz.
102102

103-
### Extracting your own custom Hook from a component {/*extracting-your-own-custom-hook-from-a-component*/}
103+
### Kendi özel Hook'unuzu bir bileşenden çıkarma {/*extracting-your-own-custom-hook-from-a-component*/}
104104

105-
Imagine for a moment that, similar to [`useState`](/reference/react/useState) and [`useEffect`](/reference/react/useEffect), there was a built-in `useOnlineStatus` Hook. Then both of these components could be simplified and you could remove the duplication between them:
105+
Bir an için hayal edin, [`useState`](/reference/react/useState) ve [`useEffect`](/reference/react/useEffect) gibi, yerleşik bir `useOnlineStatus` Hook'u olsaydı. O zaman bu iki bileşen de basitleştirilebilir ve aralarındaki tekrarı kaldırabilirsiniz:
106106

107107
```js {2,7}
108108
function StatusBar() {
109109
const isOnline = useOnlineStatus();
110-
return <h1>{isOnline ? 'Online' : 'Disconnected'}</h1>;
110+
return <h1>{isOnline ? 'Çevrimici' : 'Bağlantı kopmuş'}</h1>;
111111
}
112112

113113
function SaveButton() {
114114
const isOnline = useOnlineStatus();
115115

116116
function handleSaveClick() {
117-
console.log('Progress saved');
117+
console.log('İlerleme kaydedildi');
118118
}
119119

120120
return (
121121
<button disabled={!isOnline} onClick={handleSaveClick}>
122-
{isOnline ? 'Save progress' : 'Reconnecting...'}
122+
{isOnline ? 'İlerlemeyi kaydet' : 'Yeniden bağlanılıyor...'}
123123
</button>
124124
);
125125
}
126126
```
127127

128-
Although there is no such built-in Hook, you can write it yourself. Declare a function called `useOnlineStatus` and move all the duplicated code into it from the components you wrote earlier:
128+
Yerleşik bir Hook bulunmasa da, kendiniz yazabilirsiniz. `useOnlineStatus` adında bir fonksiyon oluşturun ve daha önce yazdığınız bileşenlerdeki tekrarlanan kodu içine taşıyın:
129129

130130
```js {2-16}
131131
function useOnlineStatus() {
@@ -148,7 +148,7 @@ function useOnlineStatus() {
148148
}
149149
```
150150

151-
At the end of the function, return `isOnline`. This lets your components read that value:
151+
Fonksiyonun sonunda `isOnline`'ı döndürün. Bu, bileşenlerinizin bu değeri okumasına olanak sağlar:
152152

153153
<Sandpack>
154154

@@ -157,19 +157,19 @@ import { useOnlineStatus } from './useOnlineStatus.js';
157157

158158
function StatusBar() {
159159
const isOnline = useOnlineStatus();
160-
return <h1>{isOnline ? 'Online' : 'Disconnected'}</h1>;
160+
return <h1>{isOnline ? 'Çevrimiçi' : 'Bağlantı kopmuş'}</h1>;
161161
}
162162

163163
function SaveButton() {
164164
const isOnline = useOnlineStatus();
165165

166166
function handleSaveClick() {
167-
console.log('Progress saved');
167+
console.log('İlerleme kaydedildi');
168168
}
169169

170170
return (
171171
<button disabled={!isOnline} onClick={handleSaveClick}>
172-
{isOnline ? 'Save progress' : 'Reconnecting...'}
172+
{isOnline ? 'İlerlemeyi kaydet' : 'Yeniden bağlanılıyor...'}
173173
</button>
174174
);
175175
}
@@ -209,62 +209,62 @@ export function useOnlineStatus() {
209209

210210
</Sandpack>
211211

212-
Verify that switching the network on and off updates both components.
212+
Ağı kapatıp açmanın iki bileşeni de güncellediğini doğrulayın.
213213

214-
Now your components don't have as much repetitive logic. **More importantly, the code inside them describes *what they want to do* (use the online status!) rather than *how to do it* (by subscribing to the browser events).**
214+
Şimdi bileşenleriniz çok tekrarlı mantığa sahip değil. **Daha da önemlisi, içlerindeki kod, *nasıl yapacakları*ndan (tarayıcı olaylarına abone olarak) ziyade *ne yapmak istedikleri*ni (çevrimiçi durumu kullanın!) açıklıyor.**
215215

216-
When you extract logic into custom Hooks, you can hide the gnarly details of how you deal with some external system or a browser API. The code of your components expresses your intent, not the implementation.
216+
Mantığı özel Hook'lara çıkarttığınızda, bir harici sistem ya da tarayıcı API'si ile nasıl başa çıktığınızın zorlu ayrıntılarını gizleyebilirsiniz. Bileşenlerinizin kodu, uygulamanızın nasıl yerine getirdiğinden ziyade ne yapmak istediğinizi açıklar.
217217

218-
### Hook names always start with `use` {/*hook-names-always-start-with-use*/}
218+
### Hook isimleri her zaman `use` ile başlar {/*hook-names-always-start-with-use*/}
219219

220-
React applications are built from components. Components are built from Hooks, whether built-in or custom. You'll likely often use custom Hooks created by others, but occasionally you might write one yourself!
220+
React uygulamaları bileşenlerden oluşur. Bileşenler yerleşik veya özel olsun, Hook'lardan oluşur. Muhtemelen sıklıkla başkaları tarafından oluşturulan özel Hook'ları kullanacaksınız, ancak arada bir kendiniz de yazabilirsiniz!
221221

222-
You must follow these naming conventions:
222+
Bu isimlendirme kurallarına uymalısınız:
223223

224-
1. **React component names must start with a capital letter,** like `StatusBar` and `SaveButton`. React components also need to return something that React knows how to display, like a piece of JSX.
225-
2. **Hook names must start with `use` followed by a capital letter,** like [`useState`](/reference/react/useState) (built-in) or `useOnlineStatus` (custom, like earlier on the page). Hooks may return arbitrary values.
224+
1. **React bileşenleri büyük harfle başlamalıdır,** `StatusBar` ve `SaveButton` gibi. React bileşenleri ayrıca, JSX gibi, React'in nasıl görüntüleyeceğini bildiği bir şey döndürmelidir.
225+
2. **Hook isimleri `use` ile başlayıp büyük harfle devam etmelidir,** [`useState`](/reference/react/useState) (yerleşik) veya `useOnlineStatus` (özel, yukarıdaki örnekte olduğu gibi). Hook'lar keyfi değerler döndürebilir.
226226

227-
This convention guarantees that you can always look at a component and know where its state, Effects, and other React features might "hide". For example, if you see a `getColor()` function call inside your component, you can be sure that it can't possibly contain React state inside because its name doesn't start with `use`. However, a function call like `useOnlineStatus()` will most likely contain calls to other Hooks inside!
227+
Bu kural, sizin bir bileşene her baktığınızda onun state, efektleri ve diğer React özelliklerinin nerede "saklanabileceğini" bilmenizi garanti eder. Örneğin, bileşeninizde `getColor()` fonksiyonu çağrısı görürseniz, adının `use` ile başlamadığı için içinde React state'i içeremeyeceğinden emin olabilirsiniz. Ancak, `useOnlineStatus()` gibi bir fonksiyon çağrısı büyük olasılıkla içinde başka Hook'lara çağrı içerecektir!
228228

229229
<Note>
230230

231-
If your linter is [configured for React,](/learn/editor-setup#linting) it will enforce this naming convention. Scroll up to the sandbox above and rename `useOnlineStatus` to `getOnlineStatus`. Notice that the linter won't allow you to call `useState` or `useEffect` inside of it anymore. Only Hooks and components can call other Hooks!
231+
Eğer linter'ınız [React için yapılandırılmışsa,](/learn/editor-setup#linting) her zaman bu isimlendirme kuralını zorlayacaktır. Yukarıdaki sandbox'ta `useOnlineStatus`'u `getOnlineStatus` olarak yeniden adlandırın. Linter'ınızın artık onun içinde `useState` veya `useEffect` çağırmaya izin vermediğini fark edin. Sadece Hook'lar ve bileşenler diğer Hook'ları çağırabilir!
232232

233233
</Note>
234234

235235
<DeepDive>
236236

237-
#### Should all functions called during rendering start with the use prefix? {/*should-all-functions-called-during-rendering-start-with-the-use-prefix*/}
237+
#### Render sırasında çağrılan tüm fonksiyonlar `use` ön eki ile mi başlamalıdır? {/*should-all-functions-called-during-rendering-start-with-the-use-prefix*/}
238238

239-
No. Functions that don't *call* Hooks don't need to *be* Hooks.
239+
Hayır. Hook'ları *çağırmayan* fonksiyonlar Hook *olmak* zorunda değildir.
240240

241-
If your function doesn't call any Hooks, avoid the `use` prefix. Instead, write it as a regular function *without* the `use` prefix. For example, `useSorted` below doesn't call Hooks, so call it `getSorted` instead:
241+
Eğer fonksiyonunuz herhangi bir Hook çağırmıyorsa, `use` ön eki kullanmayın. Bunun yerine onu `use` ön eki *bulunmayan* bir sıradan fonksiyon olarak yazın. Örneğin, aşağıdaki `useSorted` Hook çağırmadığından, onu `getSorted` olarak çağırın:
242242

243243
```js
244-
// 🔴 Avoid: A Hook that doesn't use Hooks
244+
// 🔴 Kaçının: Hook kullanmayan bir Hook
245245
function useSorted(items) {
246246
return items.slice().sort();
247247
}
248248

249-
//Good: A regular function that doesn't use Hooks
249+
//İyi: Hook kullanmayan bir sıradan fonksiyon
250250
function getSorted(items) {
251251
return items.slice().sort();
252252
}
253253
```
254254

255-
This ensures that your code can call this regular function anywhere, including conditions:
255+
Bu, kodunuzun bu sıradan fonksiyonu, koşullar dahil olmak üzere herhangi bir yerde çağırabileceğinden emin olur:
256256

257257
```js
258258
function List({ items, shouldSort }) {
259259
let displayedItems = items;
260260
if (shouldSort) {
261-
//It's ok to call getSorted() conditionally because it's not a Hook
261+
//Koşullu olarak getSorted() çağırmak sorun değil çünkü o bir Hook değil
262262
displayedItems = getSorted(items);
263263
}
264264
// ...
265265
}
266266
```
267-
267+
// TODO: Continue from here
268268
You should give `use` prefix to a function (and thus make it a Hook) if it uses at least one Hook inside of it:
269269

270270
```js

0 commit comments

Comments
 (0)