[英]How can child components communicate in React React-Native?
我怎樣才能從test2()
訪問test1()
,反之亦然? 我已經知道我可以通過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')
);
最好的方法是使用某種全球事件系統。 有很多簡單的庫可以完成此操作,或者您可以輕松地自己滾動。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.