Skip to content

Commit 6d17f86

Browse files
committed
wip
1 parent d50a0d3 commit 6d17f86

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,85 @@ title: immutability
44

55
<Intro>
66

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 및 기타 값을 변이하는 것을 검증합니다.
88

99
</Intro>
1010

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

1313
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`.
1414

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

17-
### Invalid {/*invalid*/}
17+
### 잘못된 예 {/*invalid*/}
1818

1919
```js
20-
//Array push mutation
20+
//배열 push 변이
2121
function Component() {
2222
const [items, setItems] = useState([1, 2, 3]);
2323

2424
const addItem = () => {
25-
items.push(4); // Mutating!
26-
setItems(items); // Same reference, no re-render
25+
items.push(4); // 변이!
26+
setItems(items); // 같은 참조, 리렌더링 안 됨
2727
};
2828
}
2929

30-
//Object property assignment
30+
//객체 프로퍼티 할당
3131
function Component() {
3232
const [user, setUser] = useState({name: 'Alice'});
3333

3434
const updateName = () => {
35-
user.name = 'Bob'; // Mutating!
36-
setUser(user); // Same reference
35+
user.name = 'Bob'; // 변이!
36+
setUser(user); // 같은 참조
3737
};
3838
}
3939

40-
//Sort without spreading
40+
//스프레드 없이 정렬
4141
function Component() {
4242
const [items, setItems] = useState([3, 1, 2]);
4343

4444
const sortItems = () => {
45-
setItems(items.sort()); // sort mutates!
45+
setItems(items.sort()); // sort는 변이함!
4646
};
4747
}
4848
```
4949

50-
### Valid {/*valid*/}
50+
### 올바른 예 {/*valid*/}
5151

5252
```js
53-
//Create new array
53+
//새 배열 생성
5454
function Component() {
5555
const [items, setItems] = useState([1, 2, 3]);
5656

5757
const addItem = () => {
58-
setItems([...items, 4]); // New array
58+
setItems([...items, 4]); // 새 배열
5959
};
6060
}
6161

62-
//Create new object
62+
//새 객체 생성
6363
function Component() {
6464
const [user, setUser] = useState({name: 'Alice'});
6565

6666
const updateName = () => {
67-
setUser({...user, name: 'Bob'}); // New object
67+
setUser({...user, name: 'Bob'}); // 새 객체
6868
};
6969
}
7070
```
7171

72-
## Troubleshooting {/*troubleshooting*/}
72+
## 문제 해결 {/*troubleshooting*/}
7373

74-
### I need to add items to an array {/*add-items-array*/}
74+
### 배열에 항목을 추가해야 하는 경우 {/*add-items-array*/}
7575

76-
Mutating arrays with methods like `push()` won't trigger re-renders:
76+
`push()` 같은 메서드로 배열을 변이하면 리렌더링이 트리거되지 않습니다.
7777

7878
```js
79-
//Wrong: Mutating the array
79+
//잘못된 예: 배열 변이
8080
function TodoList() {
8181
const [todos, setTodos] = useState([]);
8282

8383
const addTodo = (id, text) => {
8484
todos.push({id, text});
85-
setTodos(todos); // Same array reference!
85+
setTodos(todos); // 같은 배열 참조!
8686
};
8787

8888
return (
@@ -93,16 +93,16 @@ function TodoList() {
9393
}
9494
```
9595

96-
Create a new array instead:
96+
대신 새 배열을 생성하세요.
9797

9898
```js
99-
//Better: Create a new array
99+
//더 나은 방법: 새 배열 생성
100100
function TodoList() {
101101
const [todos, setTodos] = useState([]);
102102

103103
const addTodo = (id, text) => {
104104
setTodos([...todos, {id, text}]);
105-
// Or: setTodos(todos => [...todos, {id: Date.now(), text}])
105+
// 또는: setTodos(todos => [...todos, {id: Date.now(), text}])
106106
};
107107

108108
return (
@@ -113,12 +113,12 @@ function TodoList() {
113113
}
114114
```
115115

116-
### I need to update nested objects {/*update-nested-objects*/}
116+
### 중첩된 객체를 업데이트해야 하는 경우 {/*update-nested-objects*/}
117117

118-
Mutating nested properties doesn't trigger re-renders:
118+
중첩된 프로퍼티를 변이하면 리렌더링이 트리거되지 않습니다.
119119

120120
```js
121-
//Wrong: Mutating nested object
121+
//잘못된 예: 중첩된 객체 변이
122122
function UserProfile() {
123123
const [user, setUser] = useState({
124124
name: 'Alice',
@@ -129,16 +129,16 @@ function UserProfile() {
129129
});
130130

131131
const toggleTheme = () => {
132-
user.settings.theme = 'dark'; // Mutation!
133-
setUser(user); // Same object reference
132+
user.settings.theme = 'dark'; // 변이!
133+
setUser(user); // 같은 객체 참조
134134
};
135135
}
136136
```
137137

138-
Spread at each level that needs updating:
138+
업데이트가 필요한 각 레벨에서 스프레드하세요.
139139

140140
```js
141-
//Better: Create new objects at each level
141+
//더 나은 방법: 각 레벨에서 새 객체 생성
142142
function UserProfile() {
143143
const [user, setUser] = useState({
144144
name: 'Alice',

0 commit comments

Comments
 (0)