0
所以,我基本上有這Home
組件,它具有SearchForm
組件和PostBox
組件顯示今天的API數據。更改道具值
var Home = React.createClass({
handleSubmitSearch: function (e) {
e.preventDefault();
// change the URL
},
render: function() {
return (
<div className="home">
<SearchForm
onSubmitSearch={this.handleSubmitSearch} />
<PostBox
url="http://localhost:3000/posts/today"
pollInterval={2000} />
</div>
)
}
});
的事情是,在SearchForm
提交按鈕被觸發時,我想基本上是通過發送請求到另一個API像http://localhost:3000/posts/search/query
而不是顯示今天的數據結果顯示爲PostBox
。 我的問題是,我怎樣才能改變PostBox
的url道具改爲handleSubmitSearch()
?
您不改變'道具'。組件'道具'應該被視爲不可變的。如果某個組件需要存儲可以更改的數據,請改用'state'。 – naomik