Skip to content

Commit 499f432

Browse files
authored
Merge pull request #626 from reactjs/anilcanboga/rules-of-hooks
translate rules of hooks
2 parents 241973a + 949e37c commit 499f432

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
---
2-
title: Rules of Hooks
2+
title: Hook'ların Kuralları
33
---
44

55
<Intro>
6-
Hooks are defined using JavaScript functions, but they represent a special type of reusable UI logic with restrictions on where they can be called.
6+
Hook'lar JavaScript fonksiyonları kullanılarak tanımlanır, ancak nerede çağrılabilecekleri konusunda kısıtlamaları olan özel bir yeniden kullanılabilir UI mantığı türünü temsil ederler.
77
</Intro>
88

99
<InlineToc />
1010

1111
---
1212

13-
## Only call Hooks at the top level {/*only-call-hooks-at-the-top-level*/}
13+
## Hook'ları yalnızca en üst düzeyde çağırın {/*only-call-hooks-at-the-top-level*/}
1414

15-
Functions whose names start with `use` are called [*Hooks*](/reference/react) in React.
15+
İsimleri `use` ile başlayan fonksiyonlar React'te [*Hooks*](/reference/react) olarak adlandırılır.
1616

17-
**Don’t call Hooks inside loops, conditions, nested functions, or `try`/`catch`/`finally` blocks.** Instead, always use Hooks at the top level of your React function, before any early returns. You can only call Hooks while React is rendering a function component:
17+
**Hook'ları döngüler, koşullar, iç içe fonksiyonlar veya `try`/`catch`/`finally` blokları içinde çağırmayın.** Bunun yerine, Hook'ları her zaman React fonksiyonunuzun en üst seviyesinde, herhangi bir erken dönüşten önce kullanın. Hook'ları yalnızca React bir fonksiyon bileşenini işlerken çağırabilirsiniz:
1818

19-
*Call them at the top level in the body of a [function component](/learn/your-first-component).
20-
*Call them at the top level in the body of a [custom Hook](/learn/reusing-logic-with-custom-hooks).
19+
*Bunları bir [fonksiyon bileşeninin](/learn/your-first-component) gövdesinde en üst seviyede çağırın.
20+
*Bunları bir [özel Hook](/learn/reusing-logic-with-custom-hooks)'un gövdesinde en üst düzeyde çağırın.
2121

2222
```js{2-3,8-9}
2323
function Counter() {
24-
// ✅ Good: top-level in a function component
24+
// ✅ İyi: bir işlev bileşeninde üst düzey
2525
const [count, setCount] = useState(0);
2626
// ...
2727
}
2828
2929
function useWindowWidth() {
30-
// ✅ Good: top-level in a custom Hook
30+
// ✅ İyi: özel bir Hook içinde üst düzey
3131
const [width, setWidth] = useState(window.innerWidth);
3232
// ...
3333
}
3434
```
3535

36-
It’s **not** supported to call Hooks (functions starting with `use`) in any other cases, for example:
36+
Hook'ları (`use` ile başlayan fonksiyonlar) başka herhangi bir durumda çağırmak **desteklenmez**, örneğin:
3737

38-
* 🔴 Do not call Hooks inside conditions or loops.
39-
* 🔴 Do not call Hooks after a conditional `return` statement.
40-
* 🔴 Do not call Hooks in event handlers.
41-
* 🔴 Do not call Hooks in class components.
42-
* 🔴 Do not call Hooks inside functions passed to `useMemo`, `useReducer`, or `useEffect`.
43-
* 🔴 Do not call Hooks inside `try`/`catch`/`finally` blocks.
38+
* 🔴 Hook'ları koşulların veya döngülerin içinde çağırmayın.
39+
* 🔴 Hook'ları koşullu bir `return` ifadesinden sonra çağırmayın.
40+
* 🔴 Hook'ları olay işleyicilerinde çağırmayın.
41+
* 🔴 Hook'ları sınıf bileşenlerinde çağırmayın.
42+
* 🔴 Hook'ları `useMemo`, `useReducer` veya `useEffect`'e geçirilen fonksiyonların içinde çağırmayın.
43+
* 🔴 Hook'ları `try`/`catch`/`finally` blokları içinde çağırmayın.
4444

45-
If you break these rules, you might see this error.
45+
Bu kuralları ihlal ederseniz, bu hatayı görebilirsiniz.
4646

4747
```js{3-4,11-12,20-21}
4848
function Bad({ cond }) {
4949
if (cond) {
50-
// 🔴 Bad: inside a condition (to fix, move it outside!)
50+
// 🔴 Kötü: bir durumun içinde (düzeltmek için, dışarı taşıyın!)
5151
const theme = useContext(ThemeContext);
5252
}
5353
// ...
5454
}
5555
5656
function Bad() {
5757
for (let i = 0; i < 10; i++) {
58-
// 🔴 Bad: inside a loop (to fix, move it outside!)
58+
// 🔴 Kötü: bir döngünün içinde (düzeltmek için dışarı taşıyın!)
5959
const theme = useContext(ThemeContext);
6060
}
6161
// ...
@@ -65,22 +65,22 @@ function Bad({ cond }) {
6565
if (cond) {
6666
return;
6767
}
68-
// 🔴 Bad: after a conditional return (to fix, move it before the return!)
68+
// 🔴 Kötü: koşullu dönüşten sonra (düzeltmek için dönüşten önce taşıyın!)
6969
const theme = useContext(ThemeContext);
7070
// ...
7171
}
7272
7373
function Bad() {
7474
function handleClick() {
75-
// 🔴 Bad: inside an event handler (to fix, move it outside!)
75+
// 🔴 Kötü: bir olay işleyicisinin içinde (düzeltmek için dışarı taşıyın!)
7676
const theme = useContext(ThemeContext);
7777
}
7878
// ...
7979
}
8080
8181
function Bad() {
8282
const style = useMemo(() => {
83-
// 🔴 Bad: inside useMemo (to fix, move it outside!)
83+
// 🔴 Kötü: useMemo'nun içinde (düzeltmek için dışarı taşıyın!)
8484
const theme = useContext(ThemeContext);
8585
return createStyle(theme);
8686
});
@@ -89,47 +89,47 @@ function Bad() {
8989
9090
class Bad extends React.Component {
9191
render() {
92-
// 🔴 Bad: inside a class component (to fix, write a function component instead of a class!)
92+
// 🔴 Kötü: bir sınıf bileşeninin içinde (düzeltmek için, sınıf yerine bir fonksiyon bileşeni yazın!)
9393
useEffect(() => {})
9494
// ...
9595
}
9696
}
9797
9898
function Bad() {
9999
try {
100-
// 🔴 Bad: inside try/catch/finally block (to fix, move it outside!)
100+
// 🔴 Kötü: try/catch/finally bloğu içinde (düzeltmek için dışarı taşıyın!)
101101
const [x, setX] = useState(0);
102102
} catch {
103103
const [x, setX] = useState(1);
104104
}
105105
}
106106
```
107107

108-
You can use the [`eslint-plugin-react-hooks` plugin](https://www.npmjs.com/package/eslint-plugin-react-hooks) to catch these mistakes.
108+
Bu hataları yakalamak için [`eslint-plugin-react-hooks` eklentisini](https://www.npmjs.com/package/eslint-plugin-react-hooks) kullanabilirsiniz.
109109

110110
<Note>
111111

112-
[Custom Hooks](/learn/reusing-logic-with-custom-hooks) *may* call other Hooks (that's their whole purpose). This works because custom Hooks are also supposed to only be called while a function component is rendering.
112+
[Özel Hook'lar](/learn/reusing-logic-with-custom-hooks) *diğer Hook'ları çağırabilir* (tüm amaçları budur). Bu işe yarar çünkü özel Hook'ların da yalnızca bir işlev bileşeni işlenirken çağrılması gerekir.
113113

114114
</Note>
115115

116116
---
117117

118-
## Only call Hooks from React functions {/*only-call-hooks-from-react-functions*/}
118+
## Hook'ları yalnızca React fonksiyonlarından çağırın {/*only-call-hooks-from-react-functions*/}
119119

120-
Don’t call Hooks from regular JavaScript functions. Instead, you can:
120+
Hook'ları normal JavaScript fonksiyonlarından çağırmayın. Bunun yerine şunları yapabilirsiniz:
121121

122-
Call Hooks from React function components.
123-
Call Hooks from [custom Hooks](/learn/reusing-logic-with-custom-hooks#extracting-your-own-custom-hook-from-a-component).
122+
React fonksiyon bileşenlerinden Hook'ları çağırın.
123+
Hook'ları [özel Hook'lar](/learn/reusing-logic-with-custom-hooks#extracting-your-own-custom-hook-from-a-component)'dan çağırın.
124124

125-
By following this rule, you ensure that all stateful logic in a component is clearly visible from its source code.
125+
Bu kuralı izleyerek, bir bileşendeki tüm durum mantığının kaynak kodundan açıkça görülebilmesini sağlarsınız.
126126

127127
```js {2,5}
128128
function FriendList() {
129129
const [onlineStatus, setOnlineStatus] = useOnlineStatus(); //
130130
}
131131

132-
function setOnlineStatus() { //Not a component or custom Hook!
132+
function setOnlineStatus() { //Bir bileşen veya özel Hook değil!
133133
const [onlineStatus, setOnlineStatus] = useOnlineStatus();
134134
}
135135
```

0 commit comments

Comments
 (0)