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/immutability.md
+32-32Lines changed: 32 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,85 +4,85 @@ title: immutability
4
4
5
5
<Intro>
6
6
7
-
Validates against mutating props, state, and other values that [are immutable](/reference/rules/components-and-hooks-must-be-pure#props-and-state-are-immutable).
7
+
[불변인](/reference/rules/components-and-hooks-must-be-pure#props-and-state-are-immutable) props, state 및 기타 값을 변이하는 것을 검증합니다.
8
8
9
9
</Intro>
10
10
11
-
## Rule Details {/*rule-details*/}
11
+
## 규칙 세부 사항 {/*rule-details*/}
12
12
13
13
A component’s props and state are immutable snapshots. Never mutate them directly. Instead, pass new props down, and use the setter function from `useState`.
14
14
15
-
## Common Violations {/*common-violations*/}
15
+
## 일반적인 위반 사례 {/*common-violations*/}
16
16
17
-
### Invalid {/*invalid*/}
17
+
### 잘못된 예 {/*invalid*/}
18
18
19
19
```js
20
-
// ❌ Array push mutation
20
+
// ❌ 배열 push 변이
21
21
functionComponent() {
22
22
const [items, setItems] =useState([1, 2, 3]);
23
23
24
24
constaddItem= () => {
25
-
items.push(4); //Mutating!
26
-
setItems(items); //Same reference, no re-render
25
+
items.push(4); //변이!
26
+
setItems(items); //같은 참조, 리렌더링 안 됨
27
27
};
28
28
}
29
29
30
-
// ❌ Object property assignment
30
+
// ❌ 객체 프로퍼티 할당
31
31
functionComponent() {
32
32
const [user, setUser] =useState({name:'Alice'});
33
33
34
34
constupdateName= () => {
35
-
user.name='Bob'; //Mutating!
36
-
setUser(user); //Same reference
35
+
user.name='Bob'; //변이!
36
+
setUser(user); //같은 참조
37
37
};
38
38
}
39
39
40
-
// ❌ Sort without spreading
40
+
// ❌ 스프레드 없이 정렬
41
41
functionComponent() {
42
42
const [items, setItems] =useState([3, 1, 2]);
43
43
44
44
constsortItems= () => {
45
-
setItems(items.sort()); //sort mutates!
45
+
setItems(items.sort()); //sort는 변이함!
46
46
};
47
47
}
48
48
```
49
49
50
-
### Valid {/*valid*/}
50
+
### 올바른 예 {/*valid*/}
51
51
52
52
```js
53
-
// ✅ Create new array
53
+
// ✅ 새 배열 생성
54
54
functionComponent() {
55
55
const [items, setItems] =useState([1, 2, 3]);
56
56
57
57
constaddItem= () => {
58
-
setItems([...items, 4]); //New array
58
+
setItems([...items, 4]); //새 배열
59
59
};
60
60
}
61
61
62
-
// ✅ Create new object
62
+
// ✅ 새 객체 생성
63
63
functionComponent() {
64
64
const [user, setUser] =useState({name:'Alice'});
65
65
66
66
constupdateName= () => {
67
-
setUser({...user, name:'Bob'}); //New object
67
+
setUser({...user, name:'Bob'}); //새 객체
68
68
};
69
69
}
70
70
```
71
71
72
-
## Troubleshooting {/*troubleshooting*/}
72
+
## 문제 해결 {/*troubleshooting*/}
73
73
74
-
### I need to add items to an array {/*add-items-array*/}
74
+
### 배열에 항목을 추가해야 하는 경우 {/*add-items-array*/}
75
75
76
-
Mutating arrays with methods like `push()`won't trigger re-renders:
0 commit comments