0
我如何才能從test2()
訪問test1()
,反之亦然?我已經知道我可以通過ref_to_test1
和ref_to_test2
訪問父母中的每一個。但是,兒童組件直接調用對方的功能呢?子組件如何在React React-Native中進行通信?
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')
);