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
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.
1095
1095
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*/}
1097
1097
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.
1099
1099
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-inAPIfor. 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.
1101
1101
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:
1103
1103
1104
1104
```js {3-16,20-35}
1105
1105
function ShippingForm({ country }) {
1106
1106
const [cities, setCities] = useState(null);
1107
-
// This Effect fetches cities for a country
1107
+
// Bu Efekt bir ülke için şehirleri çeker
1108
1108
useEffect(() => {
1109
1109
let ignore = false;
1110
1110
fetch(`/api/cities?country=${country}`)
@@ -1121,7 +1121,7 @@ function ShippingForm({ country }) {
1121
1121
1122
1122
const [city, setCity] = useState(null);
1123
1123
const [areas, setAreas] = useState(null);
1124
-
// This Effect fetches areas for the selected city
1124
+
// Bu Efekt seçilen şehir için alanları çeker
1125
1125
useEffect(() => {
1126
1126
if (city) {
1127
1127
let ignore = false;
@@ -1141,7 +1141,7 @@ function ShippingForm({ country }) {
1141
1141
// ...
1142
1142
```
1143
1143
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:
1145
1145
1146
1146
```js {2-18}
1147
1147
function useData(url) {
@@ -1165,7 +1165,7 @@ function useData(url) {
1165
1165
}
1166
1166
```
1167
1167
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:
1169
1169
1170
1170
```js {2,4}
1171
1171
function ShippingForm({ country }) {
@@ -1175,39 +1175,41 @@ function ShippingForm({ country }) {
1175
1175
// ...
1176
1176
```
1177
1177
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.
1179
1179
1180
1180
<DeepDive>
1181
1181
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*/}
1183
1183
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.
1185
1185
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:
1187
1187
1188
1188
* ✅ `useData(url)`
1189
1189
* ✅ `useImpressionLog(eventName, extraData)`
1190
1190
* ✅ `useChatRoom(options)`
1191
1191
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:
1193
1193
1194
1194
* ✅ `useMediaQuery(query)`
1195
1195
* ✅ `useSocket(url)`
1196
1196
* ✅ `useIntersectionObserver(ref, options)`
1197
1197
1198
1198
**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:
1199
1199
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
+
1200
1202
* 🔴 `useMount(fn)`
1201
1203
* 🔴 `useEffectOnce(fn)`
1202
1204
* 🔴 `useUpdateEffect(fn)`
1203
1205
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:
**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.
1229
1231
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:
0 commit comments