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
@@ -57,9 +57,9 @@ var Greeting = createReactClass({
57
57
});
58
58
```
59
59
60
-
## Setting the Initial State {#setting-the-initial-state}
60
+
## 초기 State 정의 {#setting-the-initial-state}
61
61
62
-
In ES6 classes, you can define the initial state by assigning `this.state` in the constructor:
62
+
ES6 class의 생성자에서 `this.state`에 값을 할당하면 state의 초기값을 정의할 수 있습니다.
63
63
64
64
```javascript
65
65
classCounterextendsReact.Component {
@@ -71,7 +71,7 @@ class Counter extends React.Component {
71
71
}
72
72
```
73
73
74
-
With`createReactClass()`, you have to provide a separate `getInitialState`method that returns the initial state:
74
+
`createReactClass()`를 사용할 때마다 초기 state를 반환하는 `getInitialState`메서드를 제공해야만 합니다.
75
75
76
76
```javascript
77
77
var Counter =createReactClass({
@@ -82,16 +82,16 @@ var Counter = createReactClass({
82
82
});
83
83
```
84
84
85
-
## Autobinding {#autobinding}
85
+
## 자동 바인딩 {#autobinding}
86
86
87
-
In React components declared as ES6 classes, methods follow the same semantics as regular ES6 classes. This means that they don't automatically bind `this` to the instance. You'll have to explicitly use`.bind(this)` in the constructor:
87
+
ES6 class로서 선언된 React 컴포넌트에서 메서드는 일반적인 ES6 class일 때와 비슷합니다. 즉, `this`를 인스턴스에 자동으로 바인딩하지 않습니다. 따라서 이 경우에는 생성자에서 별도로`.bind(this)`를 사용해 주어야 합니다.
88
88
89
89
```javascript
90
90
classSayHelloextendsReact.Component {
91
91
constructor(props) {
92
92
super(props);
93
93
this.state= {message:'Hello!'};
94
-
//This line is important!
94
+
//이 부분이 중요합니다!
95
95
this.handleClick=this.handleClick.bind(this);
96
96
}
97
97
@@ -100,7 +100,7 @@ class SayHello extends React.Component {
100
100
}
101
101
102
102
render() {
103
-
//Because `this.handleClick` is bound, we can use it as an event handler.
103
+
// `this.handleClick`이 바인딩 되었기 때문에, 이를 이벤트 핸들러로 사용할 수 있습니다.
104
104
return (
105
105
<button onClick={this.handleClick}>
106
106
Say hello
@@ -110,7 +110,7 @@ class SayHello extends React.Component {
110
110
}
111
111
```
112
112
113
-
With`createReactClass()`, this is not necessary because it binds all methods:
113
+
반면에`createReactClass()`를 사용한다면, 알아서 모든 메서드를 바인딩하기 때문에 위의 과정이 필요하지는 않습니다.
114
114
115
115
```javascript
116
116
var SayHello =createReactClass({
@@ -132,9 +132,10 @@ var SayHello = createReactClass({
132
132
});
133
133
```
134
134
135
-
This means writing ES6 classes comes with a little more boilerplate code for event handlers, but the upside is slightly better performance in large applications.
135
+
이는 ES6의 class를 사용해 이벤트 핸들러를 만드는 경우에는 다른 방법으로 처리할 때 보다 반복되는 코드가 많아진다는 뜻입니다. 하지만 큰 규모의 애플리케이션에서는 class를 사용하는 경우에 성능이 조금 더 좋아집니다.
136
136
137
-
If the boilerplate code is too unattractive to you, you may enable the **experimental**[Class Properties](https://babeljs.io/docs/plugins/transform-class-properties/) syntax proposal with Babel:
137
+
138
+
보일러플레이트 코드를 정 쓰기 싫다면, **실험적인**[Class Properties](https://babeljs.io/docs/plugins/transform-class-properties/) 문법을 Babel을 통해 사용할 수도 있습니다.
138
139
139
140
140
141
```javascript
@@ -143,8 +144,8 @@ class SayHello extends React.Component {
143
144
super(props);
144
145
this.state= {message:'Hello!'};
145
146
}
146
-
//WARNING: this syntax is experimental!
147
-
//Using an arrow here binds the method:
147
+
//경고: 이 문법은 실험적입니다!
148
+
//화살표 함수를 통해 메서드를 바인딩합니다.
148
149
handleClick= () => {
149
150
alert(this.state.message);
150
151
}
@@ -159,27 +160,32 @@ class SayHello extends React.Component {
159
160
}
160
161
```
161
162
162
-
Please note that the syntax above is **experimental** and the syntax may change, or the proposal might not make it into the language.
163
+
위 코드에서 쓰인 문법은 **실험적인** 상태이므로 그 내용이 변할 수 있거나, JavaScript에 반영되지 않을 수 있습니다.
164
+
163
165
164
-
If you'd rather play it safe, you have a few options:
166
+
안전한 길을 원한다면 몇 가지 선택지가 있습니다.
165
167
166
-
*Bind methods in the constructor.
167
-
*Use arrow functions, e.g. `onClick={(e) => this.handleClick(e)}`.
168
-
*Keep using `createReactClass`.
168
+
*생성자에서 메서드들을 바인딩합니다.
169
+
*`onClick={(e) => this.handleClick(e)}`와 같이 화살표 함수를 사용합니다.
170
+
*`createReactClass`를 계속 사용합니다.
169
171
170
172
## Mixins {#mixins}
171
173
172
-
>**Note:**
174
+
>**주의**
173
175
>
174
-
>ES6 launched without any mixin support. Therefore, there is no support for mixins when you use React with ES6 classes.
176
+
>ES6에서는 처음부터 mixin에 대한 어떠한 지원도 없었습니다. 따라서, React에서 ES6 class를 사용하고자 하는 경우에도 mixin에 대한 별도의 지원은 없습니다.
175
177
>
176
-
>**We also found numerous issues in codebases using mixins, [and don't recommend using them in the new code](/blog/2016/07/13/mixins-considered-harmful.html).**
177
178
>
178
-
>This section exists only for the reference.
179
+
>**또한 저희 팀은 mixin을 사용한 Codebase에서 수 많은 문제점들을 발견했습니다. 이에 따라 저희는 [새로 작성하는 코드에서는 mixin을 사용하지 않는 것을 추천드립니다.](/blog/2016/07/13/mixins-considered-harmful.html)**
180
+
181
+
>
182
+
>해당 글은 참고목적으로만 보시길 바랍니다.
183
+
184
+
가끔은 전혀 다른 컴포넌트들이 어느 정도 유사한 기능을 공유할 수도 있습니다. 간혹 발생하는 이러한 경우를 번역과 링크에 관한 [횡단 관심사](https://ko.wikipedia.org/wiki/횡단_관심사)라고 부릅니다.
185
+
이 문제에 대한 대처법으로서 `createReactClass`를 통해 더 이상 쓰이지 않는 코드인 `mixins`을 사용할 수 있습니다.
179
186
180
-
Sometimes very different components may share some common functionality. These are sometimes called [cross-cutting concerns](https://en.wikipedia.org/wiki/Cross-cutting_concern). `createReactClass` lets you use a legacy `mixins` system for that.
187
+
mixin을 사용하는 흔한 예로는 시간 간격을 두고 반복적으로 스스로 내용을 갱신하는 컴포넌트를 만들고자 할 경우가 있습니다. 이는 `setInterval()`을 사용하면 간단하게 만들 수 있지만, 메모리를 절약하기 위해서 컴포넌트를 더 이상 사용하지 않을 때 이를 취소하는 것이 중요합니다. 리액트는 [생명주기 메서드](/docs/react-component.html#the-component-lifecycle)를 제공합니다. 생명주기 메서드는 컴포넌트가 생성되거나 파괴되기 직전에 이를 알려주는 역할을 합니다. 생명주기 메서드를 이용하는 간단한 mixin을 만들어 보겠습니다. 이 mixin은 컴포넌트가 파괴될 때 자동으로 정리되는 `setInterval()` 함수 기능을 제공해 줍니다.
181
188
182
-
One common use case is a component wanting to update itself on a time interval. It's easy to use `setInterval()`, but it's important to cancel your interval when you don't need it anymore to save memory. React provides [lifecycle methods](/docs/react-component.html#the-component-lifecycle) that let you know when a component is about to be created or destroyed. Let's create a simple mixin that uses these methods to provide an easy `setInterval()` function that will automatically get cleaned up when your component is destroyed.
183
189
184
190
```javascript
185
191
var SetIntervalMixin = {
@@ -197,12 +203,12 @@ var SetIntervalMixin = {
197
203
var createReactClass =require('create-react-class');
198
204
199
205
var TickTock =createReactClass({
200
-
mixins: [SetIntervalMixin], //Use the mixin
206
+
mixins: [SetIntervalMixin], //mixin을 사용
201
207
getInitialState:function() {
202
208
return {seconds:0};
203
209
},
204
210
componentDidMount:function() {
205
-
this.setInterval(this.tick, 1000); //Call a method on the mixin
If a component is using multiple mixins and several mixins define the same lifecycle method (i.e. several mixins want to do some cleanup when the component is destroyed), all of the lifecycle methods are guaranteed to be called. Methods defined on mixins run in the order mixins were listed, followed by a method call on the component.
231
+
하나의 컴포넌트가 같은 생명주기 메서드를 정의한 여러 mixin을 사용한다고 생각해봅시다. 예를 든다면, mixin들이 컴포넌트가 파괴될 때 어떠한 정리 동작을 하려고 할 수도 있습니다. 이 때는 모든 생명주기 메서드의 호출이 보장됩니다. mixin에서 정의된 생명주기 메서드들은 mixin이 나열된 순서대로 작동되며 그 뒤에 컴포넌트의 메서드가 호출됩니다.
0 commit comments