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')
);