我有这个疑问,我还没有能够谷歌,但我有这个反应组件,我想使用componentWillMount()方法使用回流存储更新它的状态 .
我能够更新商店中的状态,但是使用this.trigger从商店更新它的状态并没有给我更新状态的数据让我感到困惑 . 如何获取数据的更新状态 .
这是我的组件目前的样子
var Challenges = React.createClass({
contextTypes: {
router: React.PropTypes.func
},
mixins: [Reflux.connect(ChallengeStore,'challenges')],
getInitialState: function() {
return {
challenges: []
}
}
componentDidMount: function() {
var trackId = this.props.params.trackId; // the url
ChallengeActions.GetChallenges(trackId);
console.log(this.state);
},
render: function () {
return(
<div>
<h1>{ this.state.challenges.title }</h1> <List challenges={ this.state.challenges } />
</div>
);
}
});
我的商店在这里
var ChallengeStore = Reflux.createStore({
listenables: ChallengeActions,
onGetChallenges: function(url) {
var items = ChallengeService.getChallenges(url);
this.trigger({
challenges: items
});
}
});
1 回答
在本周找出Reflux的同时进入这个阶段 .
问题是
Reflux.connect
只连接商店似乎缺少的商店getInitialState()
.如per the docs:
除非你的商店's initial state is consistent across all it'听众,我发现最好只使用
Reflux.listenTo()
: