Skip to content

Commit 6b92185

Browse files
ymin1103simsim0709
authored andcommitted
Translate React Without ES6 (#29)
* Translate React Without ES6 * Feedback applied * feedback applied * feedback applied * feedback applied * Fix some text * Update react-without-es6.md
1 parent af74afc commit 6b92185

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

content/docs/react-without-es6.md

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
id: react-without-es6
3-
title: React Without ES6
3+
title: ES6 없이 사용하는 React
44
permalink: docs/react-without-es6.html
55
---
66

7-
Normally you would define a React component as a plain JavaScript class:
7+
보통 리액트 컴포넌트를 정의할 때 JavaScript의 class를 사용한다면 이와 같을 겁니다.
88

99
```javascript
1010
class Greeting extends React.Component {
@@ -14,7 +14,7 @@ class Greeting extends React.Component {
1414
}
1515
```
1616

17-
If you don't use ES6 yet, you may use the `create-react-class` module instead:
17+
아직 ES6를 사용하지 않는다면, 그 대신 `create-react-class` 모듈을 사용할 수도 있습니다.
1818

1919

2020
```javascript
@@ -26,11 +26,11 @@ var Greeting = createReactClass({
2626
});
2727
```
2828

29-
The API of ES6 classes is similar to `createReactClass()` with a few exceptions.
29+
ES6 class의 API는 몇몇 차이점을 제외하고는 `createReactClass()`와 비슷합니다.
3030

31-
## Declaring Default Props {#declaring-default-props}
31+
## Props 기본값 선언 {#declaring-default-props}
3232

33-
With functions and ES6 classes `defaultProps` is defined as a property on the component itself:
33+
함수와 ES6의 class를 통해 `defaultProps`를 컴포넌트 그 자체의 속성으로서 정의할 수 있습니다.
3434

3535
```javascript
3636
class Greeting extends React.Component {
@@ -42,7 +42,7 @@ Greeting.defaultProps = {
4242
};
4343
```
4444

45-
With `createReactClass()`, you need to define `getDefaultProps()` as a function on the passed object:
45+
`createReactClass()`를 사용한다면, 인자로 넘겨지는 객체 내에서 `getDefaultProps()`를 함수로 정의해야 합니다.
4646

4747
```javascript
4848
var Greeting = createReactClass({
@@ -57,9 +57,9 @@ var Greeting = createReactClass({
5757
});
5858
```
5959

60-
## Setting the Initial State {#setting-the-initial-state}
60+
## 초기 State 정의 {#setting-the-initial-state}
6161

62-
In ES6 classes, you can define the initial state by assigning `this.state` in the constructor:
62+
ES6 class의 생성자에서 `this.state`에 값을 할당하면 state의 초기값을 정의할 수 있습니다.
6363

6464
```javascript
6565
class Counter extends React.Component {
@@ -71,7 +71,7 @@ class Counter extends React.Component {
7171
}
7272
```
7373

74-
With `createReactClass()`, you have to provide a separate `getInitialState` method that returns the initial state:
74+
`createReactClass()`를 사용할 때마다 초기 state를 반환하는 `getInitialState` 메서드를 제공해야만 합니다.
7575

7676
```javascript
7777
var Counter = createReactClass({
@@ -82,16 +82,16 @@ var Counter = createReactClass({
8282
});
8383
```
8484

85-
## Autobinding {#autobinding}
85+
## 자동 바인딩 {#autobinding}
8686

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)`를 사용해 주어야 합니다.
8888

8989
```javascript
9090
class SayHello extends React.Component {
9191
constructor(props) {
9292
super(props);
9393
this.state = {message: 'Hello!'};
94-
// This line is important!
94+
// 이 부분이 중요합니다!
9595
this.handleClick = this.handleClick.bind(this);
9696
}
9797

@@ -100,7 +100,7 @@ class SayHello extends React.Component {
100100
}
101101

102102
render() {
103-
// Because `this.handleClick` is bound, we can use it as an event handler.
103+
// `this.handleClick`이 바인딩 되었기 때문에, 이를 이벤트 핸들러로 사용할 수 있습니다.
104104
return (
105105
<button onClick={this.handleClick}>
106106
Say hello
@@ -110,7 +110,7 @@ class SayHello extends React.Component {
110110
}
111111
```
112112

113-
With `createReactClass()`, this is not necessary because it binds all methods:
113+
반면에 `createReactClass()`를 사용한다면, 알아서 모든 메서드를 바인딩하기 때문에 위의 과정이 필요하지는 않습니다.
114114

115115
```javascript
116116
var SayHello = createReactClass({
@@ -132,9 +132,10 @@ var SayHello = createReactClass({
132132
});
133133
```
134134

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를 사용하는 경우에 성능이 조금 더 좋아집니다.
136136

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을 통해 사용할 수도 있습니다.
138139

139140

140141
```javascript
@@ -143,8 +144,8 @@ class SayHello extends React.Component {
143144
super(props);
144145
this.state = {message: 'Hello!'};
145146
}
146-
// WARNING: this syntax is experimental!
147-
// Using an arrow here binds the method:
147+
// 경고: 이 문법은 실험적입니다!
148+
// 화살표 함수를 통해 메서드를 바인딩합니다.
148149
handleClick = () => {
149150
alert(this.state.message);
150151
}
@@ -159,27 +160,32 @@ class SayHello extends React.Component {
159160
}
160161
```
161162

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+
163165

164-
If you'd rather play it safe, you have a few options:
166+
안전한 길을 원한다면 몇 가지 선택지가 있습니다.
165167

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`를 계속 사용합니다.
169171

170172
## Mixins {#mixins}
171173

172-
>**Note:**
174+
>**주의**
173175
>
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에 대한 별도의 지원은 없습니다.
175177
>
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).**
177178
>
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`을 사용할 수 있습니다.
179186

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()` 함수 기능을 제공해 줍니다.
181188

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.
183189

184190
```javascript
185191
var SetIntervalMixin = {
@@ -197,12 +203,12 @@ var SetIntervalMixin = {
197203
var createReactClass = require('create-react-class');
198204

199205
var TickTock = createReactClass({
200-
mixins: [SetIntervalMixin], // Use the mixin
206+
mixins: [SetIntervalMixin], // mixin을 사용
201207
getInitialState: function() {
202208
return {seconds: 0};
203209
},
204210
componentDidMount: function() {
205-
this.setInterval(this.tick, 1000); // Call a method on the mixin
211+
this.setInterval(this.tick, 1000); // mixin에서 메서드를 호출
206212
},
207213
tick: function() {
208214
this.setState({seconds: this.state.seconds + 1});
@@ -222,4 +228,4 @@ ReactDOM.render(
222228
);
223229
```
224230

225-
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

Comments
 (0)