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
React relies on the order in which hooks are called to correctly preserve state between renders. Each time your component renders, React expects the exact same hooks to be called in the exact same order. When hooks are called conditionally or in loops, React loses track of which state corresponds to which hook call, leading to bugs like state mismatches and "Rendered fewer/more hooks than expected" errors.
13
+
React는 Hook이 호출되는 순서에 의존하여 렌더링 간에 state를 올바르게 보존합니다. 컴포넌트가 렌더링될 때마다 React는 정확히 같은 Hook이 정확히 같은 순서로 호출되기를 기대합니다. Hook이 조건부로 호출되거나 루프에서 호출되면 React는 어떤 state가 어떤 Hook 호출에 해당하는지 추적할 수 없게 되어 state 불일치와 "Rendered fewer/more hooks than expected" 오류 같은 버그가 발생합니다.
14
14
15
-
## Common Violations {/*common-violations*/}
15
+
## 일반적인 위반 사례 {/*common-violations*/}
16
16
17
-
These patterns violate the Rules of Hooks:
17
+
다음 패턴들은 Hook의 규칙을 위반합니다.
18
18
19
-
-**Hooks in conditions** (`if`/`else`, ternary, `&&`/`||`)
20
-
-**Hooks in loops** (`for`, `while`, `do-while`)
21
-
-**Hooks after early returns**
22
-
-**Hooks in callbacks/event handlers**
23
-
-**Hooks in async functions**
24
-
-**Hooks in class methods**
25
-
-**Hooks at module level**
19
+
-**조건문의 Hook** (`if`/`else`, 삼항 연산자, `&&`/`||`)
20
+
-**루프의 Hook** (`for`, `while`, `do-while`)
21
+
-**조기 return 이후의 Hook**
22
+
-**콜백/이벤트 핸들러의 Hook**
23
+
-**async 함수의 Hook**
24
+
-**클래스 메서드의 Hook**
25
+
-**모듈 레벨의 Hook**
26
26
27
27
<Note>
28
28
29
-
### `use`hook {/*use-hook*/}
29
+
### `use`Hook {/*use-hook*/}
30
30
31
-
The `use`hook is different from other React hooks. You can call it conditionally and in loops:
31
+
`use`Hook은 다른 React Hook과 다릅니다. 조건부로 호출하거나 루프에서 호출할 수 있습니다.
32
32
33
33
```js
34
-
// ✅ `use` can be conditional
34
+
// ✅ `use`는 조건문에서 호출 가능
35
35
if (shouldFetch) {
36
36
constdata=use(fetchPromise);
37
37
}
38
38
39
-
// ✅ `use` can be in loops
39
+
// ✅ `use`는 루프에서 호출 가능
40
40
for (constpromiseof promises) {
41
41
results.push(use(promise));
42
42
}
43
43
```
44
44
45
-
However,`use` still has restrictions:
46
-
-Can't be wrapped in try/catch
47
-
-Must be called inside a component or hook
45
+
하지만`use`에는 여전히 제약이 있습니다.
46
+
-`try`/`catch`로 감쌀 수 없습니다.
47
+
-컴포넌트나 Hook 내부에서 호출해야 합니다.
48
48
49
-
Learn more: [`use` API Reference](/reference/react/use)
### I want to fetch data based on some condition {/*conditional-data-fetching*/}
109
+
### 조건에 따라 데이터를 가져오고 싶은 경우 {/*conditional-data-fetching*/}
110
110
111
-
You're trying to conditionally call useEffect:
111
+
`useEffect`를 조건부로 호출하려고 합니다.
112
112
113
113
```js
114
-
// ❌ Conditional hook
114
+
// ❌ 조건부 Hook
115
115
if (isLoggedIn) {
116
116
useEffect(() => {
117
117
fetchUserData();
118
118
}, []);
119
119
}
120
120
```
121
121
122
-
Call the hook unconditionally, check condition inside:
122
+
Hook을 무조건 호출하고 내부에서 조건을 확인하세요.
123
123
124
124
```js
125
-
// ✅ Condition inside hook
125
+
// ✅ Hook 내부의 조건
126
126
useEffect(() => {
127
127
if (isLoggedIn) {
128
128
fetchUserData();
@@ -132,37 +132,37 @@ useEffect(() => {
132
132
133
133
<Note>
134
134
135
-
There are better ways to fetch data rather than in a useEffect. Consider using React Query, useSWR, or React Router 6.4+ for data fetching. These solutions handle deduplicating requests, caching responses, and avoiding network waterfalls.
135
+
`useEffect`에서 데이터를 가져오는<sup>Fetch</sup> 것보다 더 나은 방법이 있습니다. 데이터 가져오기에는 React Query, useSWR 또는 React Router 6.4+를 사용하는 것을 고려하세요. 이러한 솔루션은 요청 중복 제거, 응답 캐싱, 네트워크 워터폴 방지를 처리합니다.
Always call useState, conditionally set the initial value:
154
+
항상 `useState`를 호출하고 초기값을 조건부로 설정하세요.
155
155
156
156
```js
157
-
// ✅ Conditional initial value
157
+
// ✅ 조건부 초기값
158
158
const [permissions, setPermissions] =useState(
159
159
userType ==='admin'? adminPerms : userPerms
160
160
);
161
161
```
162
162
163
-
## Options {/*options*/}
163
+
## 옵션 {/*options*/}
164
164
165
-
You can configure custom effect hooks using shared ESLint settings (available in `eslint-plugin-react-hooks` 6.1.1 and later):
165
+
공유 ESLint 설정을 사용하여 커스텀 Effect Hook을 설정할 수 있습니다 (`eslint-plugin-react-hooks` 6.1.1 이상에서 사용 가능).
166
166
167
167
```js
168
168
{
@@ -174,6 +174,6 @@ You can configure custom effect hooks using shared ESLint settings (available in
174
174
}
175
175
```
176
176
177
-
-`additionalEffectHooks`: Regex pattern matching custom hooks that should be treated as effects. This allows`useEffectEvent`and similar event functions to be called from your custom effect hooks.
177
+
-`additionalEffectHooks`: Effect로 취급되어야 하는 커스텀 Hook을 일치시키는 정규식 패턴입니다. 이를 통해`useEffectEvent`및 유사한 이벤트 함수를 커스텀 Effect Hook에서 호출할 수 있습니다.
178
178
179
-
This shared configuration is used by both `rules-of-hooks` and `exhaustive-deps`rules, ensuring consistent behavior across all hook-related linting.
179
+
이 공유 설정은 `rules-of-hooks`와 `exhaustive-deps`규칙 모두에서 사용되어 모든 Hook 관련 린트에서 일관된 동작을 보장합니다.
0 commit comments