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
Copy file name to clipboardExpand all lines: src/content/reference/eslint-plugin-react-hooks/lints/globals.md
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,55 +4,55 @@ title: globals
4
4
5
5
<Intro>
6
6
7
-
Validates against assignment/mutation of globals during render, part of ensuring that [side effects must run outside of render](/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render).
7
+
렌더링 중 전역 변수의 할당/변이를 검증합니다. 이는 [사이드 이펙트는 렌더링 외부에서 실행되어야 합니다](/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) 규칙을 보장하는 일부입니다.
8
8
9
9
</Intro>
10
10
11
-
## Rule Details {/*rule-details*/}
11
+
## 규칙 세부 사항 {/*rule-details*/}
12
12
13
-
Global variables exist outside React's control. When you modify them during render, you break React's assumption that rendering is pure. This can cause components to behave differently in development vs production, break Fast Refresh, and make your app impossible to optimize with features like React Compiler.
13
+
전역 변수는 React의 제어 범위 밖에 존재합니다. 렌더링 중에 전역 변수를 수정하면 렌더링이 순수하다는 React의 가정을 깨뜨립니다. 이로 인해 컴포넌트가 개발 환경과 프로덕션 환경에서 다르게 동작하거나, Fast Refresh가 중단되거나, React 컴파일러 같은 기능으로 앱을 최적화할 수 없게 됩니다.
14
14
15
-
### Invalid {/*invalid*/}
15
+
### 잘못된 예 {/*invalid*/}
16
16
17
-
Examples of incorrect code for this rule:
17
+
이 규칙에 대한 잘못된 코드 예시입니다.
18
18
19
19
```js
20
-
// ❌ Global counter
20
+
// ❌ 전역 카운터
21
21
let renderCount =0;
22
22
functionComponent() {
23
-
renderCount++; //Mutating global
23
+
renderCount++; //전역 변수 변이
24
24
return<div>Count: {renderCount}</div>;
25
25
}
26
26
27
-
// ❌ Modifying window properties
27
+
// ❌ window 프로퍼티 수정
28
28
functionComponent({userId}) {
29
-
window.currentUser= userId; //Global mutation
29
+
window.currentUser= userId; //전역 변이
30
30
return<div>User: {userId}</div>;
31
31
}
32
32
33
-
// ❌ Global array push
33
+
// ❌ 전역 배열 push
34
34
constevents= [];
35
35
functionComponent({event}) {
36
-
events.push(event); //Mutating global array
36
+
events.push(event); //전역 배열 변이
37
37
return<div>Events: {events.length}</div>;
38
38
}
39
39
40
-
// ❌ Cache manipulation
40
+
// ❌ 캐시 조작
41
41
constcache= {};
42
42
functionComponent({id}) {
43
43
if (!cache[id]) {
44
-
cache[id] =fetchData(id); //Modifying cache during render
0 commit comments