@@ -81,14 +81,11 @@ class Modal extends React.Component {
81
81
}
82
82
83
83
componentDidMount() {
84
- // The portal element is inserted in the DOM tree after
85
- // the Modal's children are mounted, meaning that children
86
- // will be mounted on a detached DOM node. If a child
87
- // component requires to be attached to the DOM tree
88
- // immediately when mounted, for example to measure a
89
- // DOM node, or uses 'autoFocus' in a descendant, add
90
- // state to Modal and only render the children when Modal
91
- // is inserted in the DOM tree.
84
+ // ポータルの要素が DOM ツリーに挿入されるのは、 Modal の子要素がマウントされた後になります。
85
+ // つまり、子要素は一旦どこにも結びつかない DOM ノードへとマウントされるということです。
86
+ // もし子コンポーネントがマウント後すぐに DOM ツリーに結びついてほしい ――
87
+ // たとえば DOM ノードの大きさを測りたい、子孫要素で `autoFocus` を使いたいなど
88
+ // ―― 場合は、 Modal に状態を持たせて子要素が DOM ツリーに入ったときだけ描画されるようにしましょう。
92
89
modalRoot.appendChild(this.el);
93
90
}
94
91
@@ -112,9 +109,9 @@ class Parent extends React.Component {
112
109
}
113
110
114
111
handleClick() {
115
- // This will fire when the button in Child is clicked,
116
- // updating Parent's state, even though button
117
- // is not direct descendant in the DOM.
112
+ // これは Child 内のボタンがクリックされた時に発行され、
113
+ // Parent の state を更新します。
114
+ // たとえそのボタンが DOM 上では直系の子孫でなかったとしてもです。
118
115
this.setState(state => ({
119
116
clicks: state.clicks + 1
120
117
}));
@@ -139,8 +136,8 @@ class Parent extends React.Component {
139
136
}
140
137
141
138
function Child() {
142
- // The click event on this button will bubble up to parent,
143
- // because there is no ' onClick' attribute defined
139
+ // クリックするとイベントが親に伝播します。
140
+ // なぜならここには ` onClick` 属性が定義されてないからです。
144
141
return (
145
142
<div className="modal">
146
143
<button>Click</button>
0 commit comments