diff --git a/content/docs/react-without-es6.md b/content/docs/react-without-es6.md index 8b54d0981..b0c914722 100644 --- a/content/docs/react-without-es6.md +++ b/content/docs/react-without-es6.md @@ -1,10 +1,10 @@ --- id: react-without-es6 -title: React Without ES6 +title: ES6 없이 사용하는 React permalink: docs/react-without-es6.html --- -Normally you would define a React component as a plain JavaScript class: +보통 리액트 컴포넌트를 정의할 때 JavaScript의 class를 사용한다면 이와 같을 겁니다. ```javascript class Greeting extends React.Component { @@ -14,7 +14,7 @@ class Greeting extends React.Component { } ``` -If you don't use ES6 yet, you may use the `create-react-class` module instead: +아직 ES6를 사용하지 않는다면, 그 대신 `create-react-class` 모듈을 사용할 수도 있습니다. ```javascript @@ -26,11 +26,11 @@ var Greeting = createReactClass({ }); ``` -The API of ES6 classes is similar to `createReactClass()` with a few exceptions. +ES6 class의 API는 몇몇 차이점을 제외하고는 `createReactClass()`와 비슷합니다. -## Declaring Default Props {#declaring-default-props} +## Props 기본값 선언 {#declaring-default-props} -With functions and ES6 classes `defaultProps` is defined as a property on the component itself: +함수와 ES6의 class를 통해 `defaultProps`를 컴포넌트 그 자체의 속성으로서 정의할 수 있습니다. ```javascript class Greeting extends React.Component { @@ -42,7 +42,7 @@ Greeting.defaultProps = { }; ``` -With `createReactClass()`, you need to define `getDefaultProps()` as a function on the passed object: +`createReactClass()`를 사용한다면, 인자로 넘겨지는 객체 내에서 `getDefaultProps()`를 함수로 정의해야 합니다. ```javascript var Greeting = createReactClass({ @@ -57,9 +57,9 @@ var Greeting = createReactClass({ }); ``` -## Setting the Initial State {#setting-the-initial-state} +## 초기 State 정의 {#setting-the-initial-state} -In ES6 classes, you can define the initial state by assigning `this.state` in the constructor: +ES6 class의 생성자에서 `this.state`에 값을 할당하면 state의 초기값을 정의할 수 있습니다. ```javascript class Counter extends React.Component { @@ -71,7 +71,7 @@ class Counter extends React.Component { } ``` -With `createReactClass()`, you have to provide a separate `getInitialState` method that returns the initial state: + `createReactClass()`를 사용할 때마다 초기 state를 반환하는 `getInitialState` 메서드를 제공해야만 합니다. ```javascript var Counter = createReactClass({ @@ -82,16 +82,16 @@ var Counter = createReactClass({ }); ``` -## Autobinding {#autobinding} +## 자동 바인딩 {#autobinding} -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: +ES6 class로서 선언된 React 컴포넌트에서 메서드는 일반적인 ES6 class일 때와 비슷합니다. 즉, `this`를 인스턴스에 자동으로 바인딩하지 않습니다. 따라서 이 경우에는 생성자에서 별도로 `.bind(this)`를 사용해 주어야 합니다. ```javascript class SayHello extends React.Component { constructor(props) { super(props); this.state = {message: 'Hello!'}; - // This line is important! + // 이 부분이 중요합니다! this.handleClick = this.handleClick.bind(this); } @@ -100,7 +100,7 @@ class SayHello extends React.Component { } render() { - // Because `this.handleClick` is bound, we can use it as an event handler. + // `this.handleClick`이 바인딩 되었기 때문에, 이를 이벤트 핸들러로 사용할 수 있습니다. return (