From 390eeed9d73a3a24fb1b691f25d029b63d792338 Mon Sep 17 00:00:00 2001 From: godsenal Date: Mon, 11 Feb 2019 10:48:51 +0900 Subject: [PATCH 1/6] Translate handling events --- content/docs/handling-events.md | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/content/docs/handling-events.md b/content/docs/handling-events.md index a8d3a1f51..d3b18ded2 100644 --- a/content/docs/handling-events.md +++ b/content/docs/handling-events.md @@ -1,6 +1,6 @@ --- id: handling-events -title: Handling Events +title: 이벤트 제어하기 permalink: docs/handling-events.html prev: state-and-lifecycle.html next: conditional-rendering.html @@ -8,12 +8,12 @@ redirect_from: - "docs/events-ko-KR.html" --- -Handling events with React elements is very similar to handling events on DOM elements. There are some syntactic differences: +React 엘리먼트에서 이벤트를 제어하는 방식은 DOM 엘리먼트에서 이벤트를 제어하는 방식과 매우 유사합니다. 몇 가지 문법적인 차이는 다음과 같습니다. -* React events are named using camelCase, rather than lowercase. -* With JSX you pass a function as the event handler, rather than a string. +* React의 이벤트는 소문자 대신 카멜케이스(camelCase)를 사용하여 명명됩니다. +* JSX를 사용하여 문자열이 아닌 함수로 이벤트 핸들러를 전달합니다. -For example, the HTML: +예를 들어, HTML은 다음과 같습니다. ```html ``` -is slightly different in React: +React에서는 약간 다릅니다. ```js{1} ``` -Another difference is that you cannot return `false` to prevent default behavior in React. You must call `preventDefault` explicitly. For example, with plain HTML, to prevent the default link behavior of opening a new page, you can write: +또 다른 차이점으로, React에서는 `false`를 반환하는 것으로 기본 동작을 방지할 수 없습니다. 반드시 `preventDefault`를 명시적으로 호출해야 합니다. 예를 들어, 일반 HTML에서는 새 페이지를 여는 링크의 기본 동작을 방지하기 위해 다음과 같은 코드를 작성합니다. ```html @@ -37,7 +37,7 @@ Another difference is that you cannot return `false` to prevent default behavior ``` -In React, this could instead be: +React에서는 다음과 같이 작성할 수 있습니다. ```js{2-5,8} function ActionLink() { @@ -54,11 +54,11 @@ function ActionLink() { } ``` -Here, `e` is a synthetic event. React defines these synthetic events according to the [W3C spec](https://www.w3.org/TR/DOM-Level-3-Events/), so you don't need to worry about cross-browser compatibility. See the [`SyntheticEvent`](/docs/events.html) reference guide to learn more. +여기서 `e`는 통합적인 이벤트입니다. React는 [W3C 스펙](https://www.w3.org/TR/DOM-Level-3-Events/)에 따라 통합적인 이벤트를 정의하기 때문에 브라우저 호환성에 대해 걱정할 필요가 없습니다. 더 자세한 사항은 [`SyntheticEvent`](/docs/events.html)을 참고하시기 바랍니다. -When using React you should generally not need to call `addEventListener` to add listeners to a DOM element after it is created. Instead, just provide a listener when the element is initially rendered. +React를 사용할 때 DOM 엘리먼트가 생성 된 후 리스너를 추가하기 위해 `addEventListener`를 호출할 필요가 없습니다. 대신, 엘리먼트가 처음 렌더될 때 리스너를 제공하면 됩니다. -When you define a component using an [ES6 class](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes), a common pattern is for an event handler to be a method on the class. For example, this `Toggle` component renders a button that lets the user toggle between "ON" and "OFF" states: +[ES6 클래스](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes)를 사용하여 컴포넌트를 정의할 때, 일반적인 패턴은 이벤트 핸들러를 클래스의 메서드로 만드는 것입니다. 예를 들어, 다음 `Toggle` 컴포넌트는 사용자가 "ON"과 "OFF" 상태를 토글 할 수 있는 버튼을 렌더합니다. ```js{6,7,10-14,18} class Toggle extends React.Component { @@ -66,7 +66,7 @@ class Toggle extends React.Component { super(props); this.state = {isToggleOn: true}; - // This binding is necessary to make `this` work in the callback + // 콜백에서 `this`가 작동하기 위해 이 바인딩이 필요합니다. this.handleClick = this.handleClick.bind(this); } @@ -91,18 +91,18 @@ ReactDOM.render( ); ``` -[**Try it on CodePen**](http://codepen.io/gaearon/pen/xEmzGg?editors=0010) +[**CodePen에서 실행하기**](http://codepen.io/gaearon/pen/xEmzGg?editors=0010) -You have to be careful about the meaning of `this` in JSX callbacks. In JavaScript, class methods are not [bound](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind) by default. If you forget to bind `this.handleClick` and pass it to `onClick`, `this` will be `undefined` when the function is actually called. +JSX 콜백안에서 `this`의 의미에 대해 주의해야 합니다. JavaScript에서 클래스 메서드는 기본적으로 [바인드](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind)되어 있지 않습니다. `this.handleClick`을 바인드 하지 않고 `onClick`에 전달하였다면, 함수가 실제 호출될 때 `this`는 `undefined`가 됩니다. -This is not React-specific behavior; it is a part of [how functions work in JavaScript](https://www.smashingmagazine.com/2014/01/understanding-javascript-function-prototype-bind/). Generally, if you refer to a method without `()` after it, such as `onClick={this.handleClick}`, you should bind that method. +이는 React만의 특수한 동작이 아니며, [JavaScript에서 함수가 작동하는 방식](https://www.smashingmagazine.com/2014/01/understanding-javascript-function-prototype-bind/)의 일부입니다. 일반적으로 `onClick={this.handleClick}`과 같이 뒤에 `()`를 사용하지 않고 메서드를 참조할 경우, 해당 메서드를 바인드 해야 합니다. -If calling `bind` annoys you, there are two ways you can get around this. If you are using the experimental [public class fields syntax](https://babeljs.io/docs/plugins/transform-class-properties/), you can use class fields to correctly bind callbacks: +만약 `bind`를 호출하는 것이 불편하다면, 이를 해결할 수 있는 두 가지 방법이 있습니다. 실험적인 [퍼블릭 클래스 필드 문법](https://babeljs.io/docs/plugins/transform-class-properties/)을 사용하고 있다면, 클래스 필드를 사용하여 콜백을 올바르게 바인드할 수 있습니다. ```js{2-6} class LoggingButton extends React.Component { - // This syntax ensures `this` is bound within handleClick. - // Warning: this is *experimental* syntax. + // 이 문법은 `this`가 handleClick 내에서 바인드되도록 합니다. + // 주의: 이 문법은 *실험적인* 문법입니다. handleClick = () => { console.log('this is:', this); } @@ -117,9 +117,9 @@ class LoggingButton extends React.Component { } ``` -This syntax is enabled by default in [Create React App](https://github.com/facebookincubator/create-react-app). +[Create React App](https://github.com/facebookincubator/create-react-app)에서는 이 문법이 기본적으로 설정되어 있습니다. -If you aren't using class fields syntax, you can use an [arrow function](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions) in the callback: +만약 클래스 필드 문법을 사용하고 있지 않다면, 콜백에 [화살표 함수](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions)를 사용하는 방법도 있습니다. ```js{7-9} class LoggingButton extends React.Component { @@ -128,7 +128,7 @@ class LoggingButton extends React.Component { } render() { - // This syntax ensures `this` is bound within handleClick + // 이 문법은 `this`가 handleClick 내에서 바인드되도록 합니다. return ( ``` -The above two lines are equivalent, and use [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) and [`Function.prototype.bind`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind) respectively. +위 두 줄은 동일하며 각각 [화살표 함수](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)와 [`Function.prototype.bind`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind)를 사용합니다. -In both cases, the `e` argument representing the React event will be passed as a second argument after the ID. With an arrow function, we have to pass it explicitly, but with `bind` any further arguments are automatically forwarded. +두 경우 모두 React 이벤트를 나타내는 `e` 인자가 ID 뒤에 두 번째 인자로 전달됩니다. 화살표 함수를 사용하면 명시적으로 인자를 전달해야 하지만 `bind`를 사용할 경우 추가 인자가 자동으로 전달됩니다. From 59b9b330b49817a445952487f34616999306c507 Mon Sep 17 00:00:00 2001 From: godsenal Date: Mon, 11 Feb 2019 16:51:46 +0900 Subject: [PATCH 2/6] Fix subtitle --- content/docs/handling-events.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/docs/handling-events.md b/content/docs/handling-events.md index d3b18ded2..3e318cab5 100644 --- a/content/docs/handling-events.md +++ b/content/docs/handling-events.md @@ -138,9 +138,9 @@ class LoggingButton extends React.Component { } ``` -이 문법의 문제점은 `LoggingButton`이 렌더될 때마다 다른 콜백이 생성된다는 것입니다. 대부분의 경우 문제가 되지 않으나, 콜백이 하위 컴포넌트에 props로서 전달된다면 그 컴포넌트들은 추가로 다시 렌더링을 수행할 수도 있습니다. 이러한 종류의 성능 문제를 피하고자, 생성자 안에 바인드하거나 클래스 필드 문법을 사용하는 것을 권장합니다. +이 문법의 문제점은 `LoggingButton`이 렌더될 때마다 다른 콜백이 생성된다는 것입니다. 대부분의 경우 문제가 되지 않으나, 콜백이 하위 컴포넌트에 props로서 전달된다면 그 컴포넌트들은 추가로 다시 렌더링을 수행할 수도 있습니다. 이러한 종류의 성능 문제를 피하고자, 생성자 안에서 바인드하거나 클래스 필드 문법을 사용하는 것을 권장합니다. -## 이벤트 핸들러에 인자 전달 {#passing-arguments-to-event-handlers} +## 이벤트 핸들러에 인자 전달하기 {#passing-arguments-to-event-handlers} 루프 내부에서는 이벤트 핸들러에 추가적인 매개변수를 전달하는 것이 일반적입니다. 예를 들어, `id`가 행의 ID일 경우 다음 코드가 모두 작동합니다. From 65b261768a5fe6dbed624951de0ee8296d7a6918 Mon Sep 17 00:00:00 2001 From: godsenal Date: Tue, 12 Feb 2019 09:24:16 +0900 Subject: [PATCH 3/6] Apply feedback --- content/docs/handling-events.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/content/docs/handling-events.md b/content/docs/handling-events.md index 3e318cab5..26d3bcc34 100644 --- a/content/docs/handling-events.md +++ b/content/docs/handling-events.md @@ -56,9 +56,9 @@ function ActionLink() { 여기서 `e`는 통합적인 이벤트입니다. React는 [W3C 스펙](https://www.w3.org/TR/DOM-Level-3-Events/)에 따라 통합적인 이벤트를 정의하기 때문에 브라우저 호환성에 대해 걱정할 필요가 없습니다. 더 자세한 사항은 [`SyntheticEvent`](/docs/events.html)을 참고하시기 바랍니다. -React를 사용할 때 DOM 엘리먼트가 생성 된 후 리스너를 추가하기 위해 `addEventListener`를 호출할 필요가 없습니다. 대신, 엘리먼트가 처음 렌더될 때 리스너를 제공하면 됩니다. +React를 사용할 때 DOM 엘리먼트가 생성 된 후 리스너를 추가하기 위해 `addEventListener`를 호출할 필요가 없습니다. 대신, 엘리먼트가 처음 렌더링될 때 리스너를 제공하면 됩니다. -[ES6 클래스](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes)를 사용하여 컴포넌트를 정의할 때, 일반적인 패턴은 이벤트 핸들러를 클래스의 메서드로 만드는 것입니다. 예를 들어, 다음 `Toggle` 컴포넌트는 사용자가 "ON"과 "OFF" 상태를 토글 할 수 있는 버튼을 렌더합니다. +[ES6 class](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Classes)를 사용하여 컴포넌트를 정의할 때, 일반적인 패턴은 이벤트 핸들러를 class의 메서드로 만드는 것입니다. 예를 들어, 다음 `Toggle` 컴포넌트는 사용자가 "ON"과 "OFF" 상태를 토글 할 수 있는 버튼을 렌더링합니다. ```js{6,7,10-14,18} class Toggle extends React.Component { @@ -93,11 +93,11 @@ ReactDOM.render( [**CodePen에서 실행하기**](http://codepen.io/gaearon/pen/xEmzGg?editors=0010) -JSX 콜백안에서 `this`의 의미에 대해 주의해야 합니다. JavaScript에서 클래스 메서드는 기본적으로 [바인드](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind)되어 있지 않습니다. `this.handleClick`을 바인드 하지 않고 `onClick`에 전달하였다면, 함수가 실제 호출될 때 `this`는 `undefined`가 됩니다. +JSX 콜백안에서 `this`의 의미에 대해 주의해야 합니다. JavaScript에서 class 메서드는 기본적으로 [바인드](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)되어 있지 않습니다. `this.handleClick`을 바인드 하지 않고 `onClick`에 전달하였다면, 함수가 실제 호출될 때 `this`는 `undefined`가 됩니다. 이는 React만의 특수한 동작이 아니며, [JavaScript에서 함수가 작동하는 방식](https://www.smashingmagazine.com/2014/01/understanding-javascript-function-prototype-bind/)의 일부입니다. 일반적으로 `onClick={this.handleClick}`과 같이 뒤에 `()`를 사용하지 않고 메서드를 참조할 경우, 해당 메서드를 바인드 해야 합니다. -만약 `bind`를 호출하는 것이 불편하다면, 이를 해결할 수 있는 두 가지 방법이 있습니다. 실험적인 [퍼블릭 클래스 필드 문법](https://babeljs.io/docs/plugins/transform-class-properties/)을 사용하고 있다면, 클래스 필드를 사용하여 콜백을 올바르게 바인드할 수 있습니다. +만약 `bind`를 호출하는 것이 불편하다면, 이를 해결할 수 있는 두 가지 방법이 있습니다. 실험적인 [public class fields 문법](https://babeljs.io/docs/plugins/transform-class-properties/)을 사용하고 있다면, class fields를 사용하여 콜백을 올바르게 바인드할 수 있습니다. ```js{2-6} class LoggingButton extends React.Component { @@ -119,7 +119,7 @@ class LoggingButton extends React.Component { [Create React App](https://github.com/facebookincubator/create-react-app)에서는 이 문법이 기본적으로 설정되어 있습니다. -만약 클래스 필드 문법을 사용하고 있지 않다면, 콜백에 [화살표 함수](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions)를 사용하는 방법도 있습니다. +만약 class fields 문법을 사용하고 있지 않다면, 콜백에 [화살표 함수](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions)를 사용하는 방법도 있습니다. ```js{7-9} class LoggingButton extends React.Component { @@ -138,7 +138,7 @@ class LoggingButton extends React.Component { } ``` -이 문법의 문제점은 `LoggingButton`이 렌더될 때마다 다른 콜백이 생성된다는 것입니다. 대부분의 경우 문제가 되지 않으나, 콜백이 하위 컴포넌트에 props로서 전달된다면 그 컴포넌트들은 추가로 다시 렌더링을 수행할 수도 있습니다. 이러한 종류의 성능 문제를 피하고자, 생성자 안에서 바인드하거나 클래스 필드 문법을 사용하는 것을 권장합니다. +이 문법의 문제점은 `LoggingButton`이 렌더링될 때마다 다른 콜백이 생성된다는 것입니다. 대부분의 경우 문제가 되지 않으나, 콜백이 하위 컴포넌트에 props로서 전달된다면 그 컴포넌트들은 추가로 다시 렌더링을 수행할 수도 있습니다. 이러한 종류의 성능 문제를 피하고자, 생성자 안에서 바인드하거나 class fields 문법을 사용하는 것을 권장합니다. ## 이벤트 핸들러에 인자 전달하기 {#passing-arguments-to-event-handlers} From f6161cde1955c556e1312cb8630cd5fcf7658322 Mon Sep 17 00:00:00 2001 From: godsenal Date: Tue, 12 Feb 2019 09:25:10 +0900 Subject: [PATCH 4/6] Apply feedback --- content/docs/handling-events.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/docs/handling-events.md b/content/docs/handling-events.md index 26d3bcc34..f9d7faa76 100644 --- a/content/docs/handling-events.md +++ b/content/docs/handling-events.md @@ -10,7 +10,7 @@ redirect_from: React 엘리먼트에서 이벤트를 제어하는 방식은 DOM 엘리먼트에서 이벤트를 제어하는 방식과 매우 유사합니다. 몇 가지 문법적인 차이는 다음과 같습니다. -* React의 이벤트는 소문자 대신 카멜케이스(camelCase)를 사용하여 명명됩니다. +* React의 이벤트는 소문자 대신 카멜케이스(camelCase)를 사용합니다. * JSX를 사용하여 문자열이 아닌 함수로 이벤트 핸들러를 전달합니다. 예를 들어, HTML은 다음과 같습니다. From e89db2402c08ae4995d9b1359d8f988d9921b662 Mon Sep 17 00:00:00 2001 From: godsenal Date: Wed, 13 Feb 2019 08:53:37 +0900 Subject: [PATCH 5/6] Apply feedback --- content/docs/handling-events.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/content/docs/handling-events.md b/content/docs/handling-events.md index f9d7faa76..eb27d33aa 100644 --- a/content/docs/handling-events.md +++ b/content/docs/handling-events.md @@ -1,6 +1,6 @@ --- id: handling-events -title: 이벤트 제어하기 +title: 이벤트 처리하기 permalink: docs/handling-events.html prev: state-and-lifecycle.html next: conditional-rendering.html @@ -8,9 +8,9 @@ redirect_from: - "docs/events-ko-KR.html" --- -React 엘리먼트에서 이벤트를 제어하는 방식은 DOM 엘리먼트에서 이벤트를 제어하는 방식과 매우 유사합니다. 몇 가지 문법적인 차이는 다음과 같습니다. +React 엘리먼트에서 이벤트를 처리하는 방식은 DOM 엘리먼트에서 이벤트를 처리하는 방식과 매우 유사합니다. 몇 가지 문법적인 차이는 다음과 같습니다. -* React의 이벤트는 소문자 대신 카멜케이스(camelCase)를 사용합니다. +* React의 이벤트는 소문자 대신 캐멀 케이스(camelCase)를 사용합니다. * JSX를 사용하여 문자열이 아닌 함수로 이벤트 핸들러를 전달합니다. 예를 들어, HTML은 다음과 같습니다. @@ -29,7 +29,7 @@ React에서는 약간 다릅니다. ``` -또 다른 차이점으로, React에서는 `false`를 반환하는 것으로 기본 동작을 방지할 수 없습니다. 반드시 `preventDefault`를 명시적으로 호출해야 합니다. 예를 들어, 일반 HTML에서는 새 페이지를 여는 링크의 기본 동작을 방지하기 위해 다음과 같은 코드를 작성합니다. +또 다른 차이점으로, React에서는 `false`를 반환해도 기본 동작을 방지할 수 없습니다. 반드시 `preventDefault`를 명시적으로 호출해야 합니다. 예를 들어, 일반 HTML에서는 새 페이지를 여는 링크의 기본 동작을 방지하기 위해 다음과 같은 코드를 작성합니다. ```html @@ -54,11 +54,11 @@ function ActionLink() { } ``` -여기서 `e`는 통합적인 이벤트입니다. React는 [W3C 스펙](https://www.w3.org/TR/DOM-Level-3-Events/)에 따라 통합적인 이벤트를 정의하기 때문에 브라우저 호환성에 대해 걱정할 필요가 없습니다. 더 자세한 사항은 [`SyntheticEvent`](/docs/events.html)을 참고하시기 바랍니다. +여기서 `e`는 합성 이벤트입니다. React는 [W3C 명세](https://www.w3.org/TR/DOM-Level-3-Events/)에 따라 통합적인 이벤트를 정의하기 때문에 브라우저 호환성에 대해 걱정할 필요가 없습니다. 더 자세한 사항은 [`합성 이벤트`](/docs/events.html)을 참고하시기 바랍니다. React를 사용할 때 DOM 엘리먼트가 생성 된 후 리스너를 추가하기 위해 `addEventListener`를 호출할 필요가 없습니다. 대신, 엘리먼트가 처음 렌더링될 때 리스너를 제공하면 됩니다. -[ES6 class](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Classes)를 사용하여 컴포넌트를 정의할 때, 일반적인 패턴은 이벤트 핸들러를 class의 메서드로 만드는 것입니다. 예를 들어, 다음 `Toggle` 컴포넌트는 사용자가 "ON"과 "OFF" 상태를 토글 할 수 있는 버튼을 렌더링합니다. +[ES6 클래스](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Classes)를 사용하여 컴포넌트를 정의할 때, 일반적인 패턴은 이벤트 핸들러를 클래스의 메서드로 만드는 것입니다. 예를 들어, 다음 `Toggle` 컴포넌트는 사용자가 "ON"과 "OFF" 상태를 토글 할 수 있는 버튼을 렌더링합니다. ```js{6,7,10-14,18} class Toggle extends React.Component { @@ -66,7 +66,7 @@ class Toggle extends React.Component { super(props); this.state = {isToggleOn: true}; - // 콜백에서 `this`가 작동하기 위해 이 바인딩이 필요합니다. + // 콜백에서 `this`가 작동하려면 아래와 같이 바인딩 해주어야 합니다. this.handleClick = this.handleClick.bind(this); } @@ -93,15 +93,15 @@ ReactDOM.render( [**CodePen에서 실행하기**](http://codepen.io/gaearon/pen/xEmzGg?editors=0010) -JSX 콜백안에서 `this`의 의미에 대해 주의해야 합니다. JavaScript에서 class 메서드는 기본적으로 [바인드](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)되어 있지 않습니다. `this.handleClick`을 바인드 하지 않고 `onClick`에 전달하였다면, 함수가 실제 호출될 때 `this`는 `undefined`가 됩니다. +JSX 콜백 안에서 `this`의 의미에 대해 주의해야 합니다. JavaScript에서 클래스 메서드는 기본적으로 [바인딩](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)되어 있지 않습니다. `this.handleClick`을 바인딩하지 않고 `onClick`에 전달하였다면, 함수가 실제 호출될 때 `this`는 `undefined`가 됩니다. -이는 React만의 특수한 동작이 아니며, [JavaScript에서 함수가 작동하는 방식](https://www.smashingmagazine.com/2014/01/understanding-javascript-function-prototype-bind/)의 일부입니다. 일반적으로 `onClick={this.handleClick}`과 같이 뒤에 `()`를 사용하지 않고 메서드를 참조할 경우, 해당 메서드를 바인드 해야 합니다. +이는 React만의 특수한 동작이 아니며, [JavaScript에서 함수가 작동하는 방식](https://www.smashingmagazine.com/2014/01/understanding-javascript-function-prototype-bind/)의 일부입니다. 일반적으로 `onClick={this.handleClick}`과 같이 뒤에 `()`를 사용하지 않고 메서드를 참조할 경우, 해당 메서드를 바인딩 해야 합니다. -만약 `bind`를 호출하는 것이 불편하다면, 이를 해결할 수 있는 두 가지 방법이 있습니다. 실험적인 [public class fields 문법](https://babeljs.io/docs/plugins/transform-class-properties/)을 사용하고 있다면, class fields를 사용하여 콜백을 올바르게 바인드할 수 있습니다. +만약 `bind`를 호출하는 것이 불편하다면, 이를 해결할 수 있는 두 가지 방법이 있습니다. 실험적인 [퍼블릭 클래스 필드 문법](https://babeljs.io/docs/plugins/transform-class-properties/)을 사용하고 있다면, 클래스 필드를 사용하여 콜백을 올바르게 바인딩할 수 있습니다. ```js{2-6} class LoggingButton extends React.Component { - // 이 문법은 `this`가 handleClick 내에서 바인드되도록 합니다. + // 이 문법은 `this`가 handleClick 내에서 바인딩되도록 합니다. // 주의: 이 문법은 *실험적인* 문법입니다. handleClick = () => { console.log('this is:', this); @@ -119,7 +119,7 @@ class LoggingButton extends React.Component { [Create React App](https://github.com/facebookincubator/create-react-app)에서는 이 문법이 기본적으로 설정되어 있습니다. -만약 class fields 문법을 사용하고 있지 않다면, 콜백에 [화살표 함수](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions)를 사용하는 방법도 있습니다. +만약 클래스 필드 문법을 사용하고 있지 않다면, 콜백에 [화살표 함수](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions)를 사용하는 방법도 있습니다. ```js{7-9} class LoggingButton extends React.Component { @@ -128,7 +128,7 @@ class LoggingButton extends React.Component { } render() { - // 이 문법은 `this`가 handleClick 내에서 바인드되도록 합니다. + // 이 문법은 `this`가 handleClick 내에서 바인딩되도록 합니다. return ( ``` -위 두 줄은 동일하며 각각 [화살표 함수](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)와 [`Function.prototype.bind`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind)를 사용합니다. +위 두 줄은 동등하며 각각 [화살표 함수](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)와 [`Function.prototype.bind`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind)를 사용합니다. 두 경우 모두 React 이벤트를 나타내는 `e` 인자가 ID 뒤에 두 번째 인자로 전달됩니다. 화살표 함수를 사용하면 명시적으로 인자를 전달해야 하지만 `bind`를 사용할 경우 추가 인자가 자동으로 전달됩니다. From 337b62e6d525b18fb0de492da1be330b23aea6a3 Mon Sep 17 00:00:00 2001 From: godsenal Date: Mon, 4 Mar 2019 12:36:51 +0900 Subject: [PATCH 6/6] Apply feedback --- content/docs/handling-events.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/docs/handling-events.md b/content/docs/handling-events.md index 38cd1f194..bf66bd405 100644 --- a/content/docs/handling-events.md +++ b/content/docs/handling-events.md @@ -54,9 +54,9 @@ function ActionLink() { } ``` -여기서 `e`는 합성 이벤트입니다. React는 [W3C 명세](https://www.w3.org/TR/DOM-Level-3-Events/)에 따라 통합적인 이벤트를 정의하기 때문에 브라우저 호환성에 대해 걱정할 필요가 없습니다. 더 자세한 사항은 [`합성 이벤트`](/docs/events.html)을 참고하시기 바랍니다. +여기서 `e`는 합성 이벤트입니다. React는 [W3C 명세](https://www.w3.org/TR/DOM-Level-3-Events/)에 따라 합성 이벤트를 정의하기 때문에 브라우저 호환성에 대해 걱정할 필요가 없습니다. 더 자세한 사항은 [`합성 이벤트`](/docs/events.html)을 참고하시기 바랍니다. -React를 사용할 때 DOM 엘리먼트가 생성 된 후 리스너를 추가하기 위해 `addEventListener`를 호출할 필요가 없습니다. 대신, 엘리먼트가 처음 렌더링될 때 리스너를 제공하면 됩니다. +React를 사용할 때 DOM 엘리먼트가 생성된 후 리스너를 추가하기 위해 `addEventListener`를 호출할 필요가 없습니다. 대신, 엘리먼트가 처음 렌더링될 때 리스너를 제공하면 됩니다. [ES6 클래스](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Classes)를 사용하여 컴포넌트를 정의할 때, 일반적인 패턴은 이벤트 핸들러를 클래스의 메서드로 만드는 것입니다. 예를 들어, 다음 `Toggle` 컴포넌트는 사용자가 "ON"과 "OFF" 상태를 토글 할 수 있는 버튼을 렌더링합니다.