Translate tip-15 to Korean
- Up to 52494f9
Jinwoo Oh committed
Mar 15, 2015 at 02:12 UTC
23a5a8907726e9d0718ebde5db3ca82a645888ad
1 file changed
+59
docs/tips/15-expose-component-functions.ko-KR.md
new
+59
@@ -0,0 +1,59 @@
1
+---
2
+id: expose-component-functions-ko-KR
3
+title: 컴포넌트 함수 드러내기
4
+layout: tips
5
+permalink: expose-component-functions-ko-KR.html
6
+prev: communicate-between-components-ko-KR.html
7
+next: references-to-components-ko-KR.html
8
+---
9
+
10
+[컴포넌트간의 통신](/react/tips/communicate-between-components-ko-KR.html)을 위한 (일반적이지 않은) 또다른 방법이 있습니다: 단순히 부모의 호출을 위해 자식 컴포넌트의 메소드를 노출하는 겁니다.
11
+
12
+할일 목록을 생각해보죠. 아이템을 클릭하면 제거되고, 하나가 남으면 애니메이션 효과를 줍니다:
13
+
14
+```js
15
+var Todo = React.createClass({
16
+ render: function() {
17
+ return <div onClick={this.props.onClick}>{this.props.title}</div>;
18
+ },
19
+
20
+ //이 컴포넌트는 `ref` 어트리뷰트를 통해 부모에게 다뤄질 것입니다
21
+ animate: function() {
22
+ console.log('%s이 애니메이팅하는것처럼 속입니다', this.props.title);
23
+ }
24
+});
25
+
26
+var Todos = React.createClass({
27
+ getInitialState: function() {
28
+ return {items: ['사과', '바나나', '크랜베리']};
29
+ },
30
+
31
+ handleClick: function(index) {
32
+ var items = this.state.items.filter(function(item, i) {
33
+ return index !== i;
34
+ });
35
+ this.setState({items: items}, function() {
36
+ if (items.length === 1) {
37
+ this.refs.item0.animate();
38
+ }
39
+ }.bind(this));
40
+ },
41
+
42
+ render: function() {
43
+ return (
44
+ <div>
45
+ {this.state.items.map(function(item, i) {
46
+ var boundClick = this.handleClick.bind(this, i);
47
+ return (
48
+ <Todo onClick={boundClick} key={i} title={item} ref={'item' + i} />
49
+ );
50
+ }, this)}
51
+ </div>
52
+ );
53
+ }
54
+});
55
+
56
+React.render(<Todos />, mountNode);
57
+```
58
+
59
+다른 방법으로는, `isLastUnfinishedItem` prop을 `todo`에 넘기는 방식으로 원하는 바를 이룰수도 있습니다. `componentDidUpdate`에서 prop을 확인하고 스스로 애니메이션 효과를 주는겁니다; 하지만 애니메이션 제어를 위해 다른 prop들을 넘기게 되면 이는 금새 난잡해질 수 있습니다.