当我尝试从ajax调用内部调度一个动作时,当存储本身得到更新时(在浏览器redux插件中检查),该组件不会收到该事件,因此不会重新渲染。 / p>
class SomeComponent extends React.Component{
constuctor (props) {
super(props);
this.someAjaxCall();
}
someAjaxCall(){
this.props.dispatch(someAction('Work'));
$.ajax({
type: "POST",
url: "someURL",
success: function(data)
{
this.props.dispatch(someAction("Does Not Work"));
}.bind(this)
});
}
render(){
return (<div></div>);
}
}
const mapStateToProps = (store, ownprops) => {
return {
store: store.get("Some_Key")
}
}
const render = (store,container) => {
let ConnectedComponent = ReactRedux.connect(this.mapStateToProps)(SomeComponent);
ReactDOM.render(
<Provider store={ store }>
<ConnectedComponent/>
</Provider>
, container);
}
const someAction = (state) => {
return {
type: 'SOME_CASE',
state: state
}
}
const reducer = (state, action) => {
switch (action.type) {
case 'SOME_CASE':{
return state.set("stateKey",action.state);
}
default: {
return state;
}
}
}
从上面的示例中,当我调用this.props.dispatch(someAction('Work'));
商店得到更新,组件获取事件并重新呈现自己。但是,当我从ajax调用的“success”函数内部调用时,商店会更新,但组件永远不会收到该事件。
答案 0 :(得分:0)
如果我错了,请纠正我。 第二个Action创建者调用不应该失败,因为someAction不是全局的。你有任何错误吗?