Skip to content

Commit 0f2bf7b

Browse files
committed
wip
1 parent 10d7c21 commit 0f2bf7b

File tree

1 file changed

+50
-50
lines changed

1 file changed

+50
-50
lines changed

src/content/reference/eslint-plugin-react-hooks/lints/rules-of-hooks.md

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,89 +4,89 @@ title: rules-of-hooks
44

55
<Intro>
66

7-
Validates that components and hooks follow the [Rules of Hooks](/reference/rules/rules-of-hooks).
7+
컴포넌트와 Hook이 [Hook의 규칙](/reference/rules/rules-of-hooks)을 따르는지 검증합니다.
88

99
</Intro>
1010

11-
## Rule Details {/*rule-details*/}
11+
## 규칙 세부 사항 {/*rule-details*/}
1212

13-
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" 오류 같은 버그가 발생합니다.
1414

15-
## Common Violations {/*common-violations*/}
15+
## 일반적인 위반 사례 {/*common-violations*/}
1616

17-
These patterns violate the Rules of Hooks:
17+
다음 패턴들은 Hook의 규칙을 위반합니다.
1818

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**
2626

2727
<Note>
2828

29-
### `use` hook {/*use-hook*/}
29+
### `use` Hook {/*use-hook*/}
3030

31-
The `use` hook is different from other React hooks. You can call it conditionally and in loops:
31+
`use` Hook은 다른 React Hook과 다릅니다. 조건부로 호출하거나 루프에서 호출할 수 있습니다.
3232

3333
```js
34-
// ✅ `use` can be conditional
34+
// ✅ `use`는 조건문에서 호출 가능
3535
if (shouldFetch) {
3636
const data = use(fetchPromise);
3737
}
3838

39-
// ✅ `use` can be in loops
39+
// ✅ `use`는 루프에서 호출 가능
4040
for (const promise of promises) {
4141
results.push(use(promise));
4242
}
4343
```
4444

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 내부에서 호출해야 합니다.
4848

49-
Learn more: [`use` API Reference](/reference/react/use)
49+
더 알아보기: [`use` API 레퍼런스](/reference/react/use)
5050

5151
</Note>
5252

53-
### Invalid {/*invalid*/}
53+
### 잘못된 예 {/*invalid*/}
5454

55-
Examples of incorrect code for this rule:
55+
이 규칙에 대한 잘못된 코드 예시입니다.
5656

5757
```js
58-
//Hook in condition
58+
//조건문의 Hook
5959
if (isLoggedIn) {
6060
const [user, setUser] = useState(null);
6161
}
6262

63-
//Hook after early return
63+
//조기 return 이후의 Hook
6464
if (!data) return <Loading />;
6565
const [processed, setProcessed] = useState(data);
6666

67-
//Hook in callback
67+
//콜백의 Hook
6868
<button onClick={() => {
6969
const [clicked, setClicked] = useState(false);
7070
}}/>
7171

72-
// ❌ `use` in try/catch
72+
//try/catch의 `use`
7373
try {
7474
const data = use(promise);
7575
} catch (e) {
76-
// error handling
76+
// 오류 처리
7777
}
7878

79-
//Hook at module level
80-
const globalState = useState(0); // Outside component
79+
//모듈 레벨의 Hook
80+
const globalState = useState(0); // 컴포넌트 외부
8181
```
8282

83-
### Valid {/*valid*/}
83+
### 올바른 예 {/*valid*/}
8484

85-
Examples of correct code for this rule:
85+
이 규칙에 대한 올바른 코드 예시입니다.
8686

8787
```js
8888
function Component({ isSpecial, shouldFetch, fetchPromise }) {
89-
//Hooks at top level
89+
//최상위 레벨의 Hook
9090
const [count, setCount] = useState(0);
9191
const [name, setName] = useState('');
9292

@@ -95,7 +95,7 @@ function Component({ isSpecial, shouldFetch, fetchPromise }) {
9595
}
9696

9797
if (shouldFetch) {
98-
// ✅ `use` can be conditional
98+
// ✅ `use`는 조건문에서 호출 가능
9999
const data = use(fetchPromise);
100100
return <div>{data}</div>;
101101
}
@@ -104,25 +104,25 @@ function Component({ isSpecial, shouldFetch, fetchPromise }) {
104104
}
105105
```
106106

107-
## Troubleshooting {/*troubleshooting*/}
107+
## 문제 해결 {/*troubleshooting*/}
108108

109-
### I want to fetch data based on some condition {/*conditional-data-fetching*/}
109+
### 조건에 따라 데이터를 가져오고 싶은 경우 {/*conditional-data-fetching*/}
110110

111-
You're trying to conditionally call useEffect:
111+
`useEffect`를 조건부로 호출하려고 합니다.
112112

113113
```js
114-
//Conditional hook
114+
//조건부 Hook
115115
if (isLoggedIn) {
116116
useEffect(() => {
117117
fetchUserData();
118118
}, []);
119119
}
120120
```
121121

122-
Call the hook unconditionally, check condition inside:
122+
Hook을 무조건 호출하고 내부에서 조건을 확인하세요.
123123

124124
```js
125-
//Condition inside hook
125+
//Hook 내부의 조건
126126
useEffect(() => {
127127
if (isLoggedIn) {
128128
fetchUserData();
@@ -132,37 +132,37 @@ useEffect(() => {
132132

133133
<Note>
134134

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+를 사용하는 것을 고려하세요. 이러한 솔루션은 요청 중복 제거, 응답 캐싱, 네트워크 워터폴 방지를 처리합니다.
136136

137-
Learn more: [Fetching Data](/learn/synchronizing-with-effects#fetching-data)
137+
더 알아보기: [데이터 가져오기](/learn/synchronizing-with-effects#fetching-data)
138138

139139
</Note>
140140

141-
### I need different state for different scenarios {/*conditional-state-initialization*/}
141+
### 다른 시나리오에 따라 다른 state가 필요한 경우 {/*conditional-state-initialization*/}
142142

143-
You're trying to conditionally initialize state:
143+
state를 조건부로 초기화하려고 합니다.
144144

145145
```js
146-
//Conditional state
146+
//조건부 state
147147
if (userType === 'admin') {
148148
const [permissions, setPermissions] = useState(adminPerms);
149149
} else {
150150
const [permissions, setPermissions] = useState(userPerms);
151151
}
152152
```
153153

154-
Always call useState, conditionally set the initial value:
154+
항상 `useState`를 호출하고 초기값을 조건부로 설정하세요.
155155

156156
```js
157-
//Conditional initial value
157+
//조건부 초기값
158158
const [permissions, setPermissions] = useState(
159159
userType === 'admin' ? adminPerms : userPerms
160160
);
161161
```
162162

163-
## Options {/*options*/}
163+
## 옵션 {/*options*/}
164164

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 이상에서 사용 가능).
166166

167167
```js
168168
{
@@ -174,6 +174,6 @@ You can configure custom effect hooks using shared ESLint settings (available in
174174
}
175175
```
176176

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에서 호출할 수 있습니다.
178178

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

Comments
 (0)