Skip to content

Commit 02ce17b

Browse files
committed
docs: translate custom hooks (50%)
1 parent f002a0d commit 02ce17b

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

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

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,38 +1010,38 @@ export function useChatRoom({ serverUrl, roomId, onReceiveMessage }) {
10101010
export function createConnection({ serverUrl, roomId }) {
10111011
// A real implementation would actually connect to the server
10121012
if (typeof serverUrl !== 'string') {
1013-
throw Error('Expected serverUrl to be a string. Received: ' + serverUrl);
1013+
throw Error(`serverUrl'in bir string olması bekleniyordu. Alınan: ` + serverUrl);
10141014
}
10151015
if (typeof roomId !== 'string') {
1016-
throw Error('Expected roomId to be a string. Received: ' + roomId);
1016+
throw Error(`roomId'nin bir string olması bekleniyordu. Alınan: ` + roomId);
10171017
}
10181018
let intervalId;
10191019
let messageCallback;
10201020
return {
10211021
connect() {
1022-
console.log(' Connecting to "' + roomId + '" room at ' + serverUrl + '...');
1022+
console.log('' + serverUrl + `'deki ` + roomId + ' odasına bağlanılıyor...');
10231023
clearInterval(intervalId);
10241024
intervalId = setInterval(() => {
10251025
if (messageCallback) {
10261026
if (Math.random() > 0.5) {
10271027
messageCallback('hey')
10281028
} else {
1029-
messageCallback('lol');
1029+
messageCallback('acayip komik');
10301030
}
10311031
}
10321032
}, 3000);
10331033
},
10341034
disconnect() {
10351035
clearInterval(intervalId);
10361036
messageCallback = null;
1037-
console.log('Disconnected from "' + roomId + '" room at ' + serverUrl + '');
1037+
console.log('❌ ' + serverUrl + `'deki ` + roomId + ' odasından ayrılındı')
10381038
},
10391039
on(event, callback) {
10401040
if (messageCallback) {
1041-
throw Error('Cannot add the handler twice.');
1041+
throw Error('İki kez yönetici eklenemez.');
10421042
}
10431043
if (event !== 'message') {
1044-
throw Error('Only "message" event is supported.');
1044+
throw Error('Sadece "message" olayı destekleniyor.');
10451045
}
10461046
messageCallback = callback;
10471047
},
@@ -1091,20 +1091,20 @@ button { margin-left: 10px; }
10911091
10921092
</Sandpack>
10931093
1094-
Notice how you no longer need to know *how* `useChatRoom` works in order to use it. You could add it to any other component, pass any other options, and it would work the same way. That's the power of custom Hooks.
1094+
`useChatRoom`'un nasıl çalıştığını artık bilmenize gerek olmadığını farkedin. Onu herhangi bir başka bileşene ekleyebilir, herhangi başka seçenekler geçirebilirsiniz, aynı şekilde çalışacaktır. Bu özel Hook'ların gücüdür.
10951095
1096-
## When to use custom Hooks {/*when-to-use-custom-hooks*/}
1096+
## Özel Hook'lar ne zaman kullanılmalıdır {/*when-to-use-custom-hooks*/}
10971097

1098-
You don't need to extract a custom Hook for every little duplicated bit of code. Some duplication is fine. For example, extracting a `useFormInput` Hook to wrap a single `useState` call like earlier is probably unnecessary.
1098+
Her ufak tekrarlanan kod parçası için bir özel Hook çıkarmanıza gerek yok. Bazı tekrarlanmalar sorun değildir. Örneğin, yukarıdaki gibi tek bir `useState` çağrısını saran bir `useFormInput` Hook'u çıkartmak muhtemelen gereksizdir.
10991099
1100-
However, whenever you write an Effect, consider whether it would be clearer to also wrap it in a custom Hook. [You shouldn't need Effects very often,](/learn/you-might-not-need-an-effect) so if you're writing one, it means that you need to "step outside React" to synchronize with some external system or to do something that React doesn't have a built-in API for. Wrapping it into a custom Hook lets you precisely communicate your intent and how the data flows through it.
1100+
Ancak, her Efekt yazdığınızda, onu özel bir Hook'a sarmanın daha net olup olmayacağını düşünün. [Efekt'lere çok sık ihtiyacınız olmamalı](/learn/you-might-not-need-an-effect) yani eğer bir Efekt yazıyorsanız, bu "React'ten dışarı çıkmak" ve bazı harici sistemlerle senkronize olmanız ya da React'in dahili bir API'sinin sağlamadığı bir şeyi yapmanız gerektiği anlamına gelir. Onu özel bir Hook'a sararak, niyetinizi ve verinin onun içinden nasıl aktığına dair bilgiyi net bir şekilde iletebilirsiniz.
11011101
1102-
For example, consider a `ShippingForm` component that displays two dropdowns: one shows the list of cities, and another shows the list of areas in the selected city. You might start with some code that looks like this:
1102+
Örneğin, iki açılır menü bileşenini gösteren bir `ShippingForm` bileşenini ele alın: birisi şehirlerin listesini, diğeri seçilen şehirdeki alanların listesini göstersin. Şöyle bir kodla başlayabilirsiniz:
11031103
11041104
```js {3-16,20-35}
11051105
function ShippingForm({ country }) {
11061106
const [cities, setCities] = useState(null);
1107-
// This Effect fetches cities for a country
1107+
// Bu Efekt bir ülke için şehirleri çeker
11081108
useEffect(() => {
11091109
let ignore = false;
11101110
fetch(`/api/cities?country=${country}`)
@@ -1121,7 +1121,7 @@ function ShippingForm({ country }) {
11211121
11221122
const [city, setCity] = useState(null);
11231123
const [areas, setAreas] = useState(null);
1124-
// This Effect fetches areas for the selected city
1124+
// Bu Efekt seçilen şehir için alanları çeker
11251125
useEffect(() => {
11261126
if (city) {
11271127
let ignore = false;
@@ -1141,7 +1141,7 @@ function ShippingForm({ country }) {
11411141
// ...
11421142
```
11431143
1144-
Although this code is quite repetitive, [it's correct to keep these Effects separate from each other.](/learn/removing-effect-dependencies#is-your-effect-doing-several-unrelated-things) They synchronize two different things, so you shouldn't merge them into one Effect. Instead, you can simplify the `ShippingForm` component above by extracting the common logic between them into your own `useData` Hook:
1144+
Bu kod biraz tekrarlayıcı olsa da, [bu Efekt'leri birbirinden ayrı tutmak doğrudur.](/learn/removing-effect-dependencies#is-your-effect-doing-several-unrelated-things) İki farklı şeyi senkronize ediyorlar, bu yüzden onları tek bir Efekt'e birleştirmemelisiniz. Bunun yerine, yukarıdaki `ShippingForm` bileşenini aralarındaki ortak mantığı kendi `useData` Hook'unuza çıkartarak basitleştirebilirsiniz:
11451145
11461146
```js {2-18}
11471147
function useData(url) {
@@ -1165,7 +1165,7 @@ function useData(url) {
11651165
}
11661166
```
11671167
1168-
Now you can replace both Effects in the `ShippingForm` components with calls to `useData`:
1168+
Şimdi `ShippingForm` içindeki her iki Efekt'i de `useData`'nın çağrılarıyla değiştirebilirsiniz:
11691169
11701170
```js {2,4}
11711171
function ShippingForm({ country }) {
@@ -1175,39 +1175,41 @@ function ShippingForm({ country }) {
11751175
// ...
11761176
```
11771177
1178-
Extracting a custom Hook makes the data flow explicit. You feed the `url` in and you get the `data` out. By "hiding" your Effect inside `useData`, you also prevent someone working on the `ShippingForm` component from adding [unnecessary dependencies](/learn/removing-effect-dependencies) to it. With time, most of your app's Effects will be in custom Hooks.
1178+
Bir özel Hook çıkarmak veri akışını aşikâr hale getirir. `url`'i içeri beslersiniz ve `data`'yı dışarı alırsınız. Efekt'inizi `useData`'nın içine "gizleyerek", `ShippingForm` bileşeninde çalışan birinin ona [gereksiz bağımlılıklar](/learn/removing-effect-dependencies) eklemesini de engellersiniz. Zamanla, uygulamanızın çoğu Efekti özel Hook'larda olacaktır.
11791179
11801180
<DeepDive>
11811181
1182-
#### Keep your custom Hooks focused on concrete high-level use cases {/*keep-your-custom-hooks-focused-on-concrete-high-level-use-cases*/}
1182+
#### Özel Hook'larınızı somut yüksek seviyeli kullanım durumlarına odaklı tutun {/*keep-your-custom-hooks-focused-on-concrete-high-level-use-cases*/}
11831183
1184-
Start by choosing your custom Hook's name. If you struggle to pick a clear name, it might mean that your Effect is too coupled to the rest of your component's logic, and is not yet ready to be extracted.
1184+
Özel Hook'unuzun adını seçerek başlayın. Eğer net bir isim seçmekte zorlanıyorsanız, bu Efek'inizin bileşeninizin geri kalan mantığına çok bağlı olduğu ve henüz çıkartılmaya hazır olmadığı anlamına gelebilir.
11851185
1186-
Ideally, your custom Hook's name should be clear enough that even a person who doesn't write code often could have a good guess about what your custom Hook does, what it takes, and what it returns:
1186+
İdeal olarak, özel Hook'unuzun adı kod yazmayan bir kişinin bile ne yaptığını, ne aldığını ve ne döndürdüğünü tahmin edebileceği kadar açık olmalıdır:
11871187
11881188
* ✅ `useData(url)`
11891189
* ✅ `useImpressionLog(eventName, extraData)`
11901190
* ✅ `useChatRoom(options)`
11911191
1192-
When you synchronize with an external system, your custom Hook name may be more technical and use jargon specific to that system. It's good as long as it would be clear to a person familiar with that system:
1192+
Dış bir sistemle senkronize olduğunuzda, özel Hook adınız daha teknik olabilir ve o sisteme özel jargon kullanabilir. Bu, o sisteme aşina bir kişi için açık olduğu sürece sorun değildir:
11931193
11941194
* ✅ `useMediaQuery(query)`
11951195
* ✅ `useSocket(url)`
11961196
* ✅ `useIntersectionObserver(ref, options)`
11971197
11981198
**Keep custom Hooks focused on concrete high-level use cases.** Avoid creating and using custom "lifecycle" Hooks that act as alternatives and convenience wrappers for the `useEffect` API itself:
11991199
1200+
**Özel Hook'larınızı somut yüksek seviyeli kullanım durumlarına odaklı tutun.** `useEffect` API'sinin kendisi için alternatifler ve kolaylık sarıcıları olan özel "lifecycle" Hook'ları oluşturmayın ve kullanmayın:
1201+
12001202
* 🔴 `useMount(fn)`
12011203
* 🔴 `useEffectOnce(fn)`
12021204
* 🔴 `useUpdateEffect(fn)`
12031205
1204-
For example, this `useMount` Hook tries to ensure some code only runs "on mount":
1206+
Örneğin, bu `useMount` Hook'u bazı kodun sadece "mount" sırasında çalışmasını sağlamaya çalışır:
12051207
12061208
```js {4-5,14-15}
12071209
function ChatRoom({ roomId }) {
12081210
const [serverUrl, setServerUrl] = useState('https://localhost:1234');
12091211
1210-
// 🔴 Avoid: using custom "lifecycle" Hooks
1212+
// 🔴 Kaçının: özel "lifecycle" Hook'ları kullanmak
12111213
useMount(() => {
12121214
const connection = createConnection({ roomId, serverUrl });
12131215
connection.connect();
@@ -1217,23 +1219,23 @@ function ChatRoom({ roomId }) {
12171219
// ...
12181220
}
12191221
1220-
// 🔴 Avoid: creating custom "lifecycle" Hooks
1222+
// 🔴 Kaçının: özel "lifecycle" Hook'ları oluşturmak
12211223
function useMount(fn) {
12221224
useEffect(() => {
12231225
fn();
1224-
}, []); // 🔴 React Hook useEffect has a missing dependency: 'fn'
1226+
}, []); // 🔴 React Hook'u useEffect'in bir bağımlılığı eksik: 'fn'
12251227
}
12261228
```
12271229
1228-
**Custom "lifecycle" Hooks like `useMount` don't fit well into the React paradigm.** For example, this code example has a mistake (it doesn't "react" to `roomId` or `serverUrl` changes), but the linter won't warn you about it because the linter only checks direct `useEffect` calls. It won't know about your Hook.
1230+
**`useMount` gibi özel "lifecycle" Hook'ları React paradigmasına pek iyi uymaz.** Örneğin, bu kod örneğinde bir hata var (`roomId` ya da `serverUrl`'deki değişikliklere "tepki" vermiyor), ama linter sizi bunun hakkında uyarmayacaktır, çünkü linter sadece doğrudan `useEffect` çağrılarını kontrol eder. Hook'unuz hakkında bilgisi olmayacaktır.
12291231
1230-
If you're writing an Effect, start by using the React API directly:
1232+
Eğer bir Efekt yazıyorsanız, React API'sini doğrudan kullanarak başlayın:
12311233
12321234
```js
12331235
function ChatRoom({ roomId }) {
12341236
const [serverUrl, setServerUrl] = useState('https://localhost:1234');
12351237
1236-
//Good: two raw Effects separated by purpose
1238+
// ✅ İyi: amaçlarına göre ayrılmış iki saf Efekt
12371239
12381240
useEffect(() => {
12391241
const connection = createConnection({ serverUrl, roomId });
@@ -1249,13 +1251,13 @@ function ChatRoom({ roomId }) {
12491251
}
12501252
```
12511253
1252-
Then, you can (but don't have to) extract custom Hooks for different high-level use cases:
1254+
Sonra, farklı yüksek seviyeli kullanım durumları için özel Hook'lar çıkartabilirsiniz (ama çıkartmak zorunda değilsiniz):
12531255
12541256
```js
12551257
function ChatRoom({ roomId }) {
12561258
const [serverUrl, setServerUrl] = useState('https://localhost:1234');
12571259
1258-
//Great: custom Hooks named after their purpose
1260+
// ✅ İyi: amaçlarına göre adlandırılmış özel Hook'lar
12591261
useChatRoom({ serverUrl, roomId });
12601262
useImpressionLog('visit_chat', { roomId });
12611263
// ...

0 commit comments

Comments
 (0)