0
test1()
にはtest2()
からアクセスできますか?私はすでに、親からそれぞれref_to_test1
とref_to_test2
を使ってアクセスできることを知っています。しかし、関数を直接お互いに呼び出す子コンポーネントはどうでしょうか?子どもの構成要素は、どのようにしてリアクションリアクションネイティブで通信できますか?
var CommentBox = React.createClass({
render: function() {
console.log(this)
return (
<div className="commentBox">
<h1>Comments</h1>
<CommentList ref={'ref_to_test1'}/>
<CommentForm ref={'ref_to_test2'}/>
</div>
);
}
});
var CommentList = React.createClass({
test1:function(){},
render: function() {
console.log(this)
return (
<div className="commentList">
Hello, world! I am a CommentList.
</div>
);
}
});
var CommentForm = React.createClass({
test2:function(){},
render: function() {
return (
<div className="commentForm">
Hello, world! I am a CommentForm.
</div>
);
}
});
ReactDOM.render(
<CommentBox />,
document.getElementById('content')
);