dispatch() 之后的代码没有被执行
Code after a dispatch() isn't being executed
我有一些代码如下所示:
减速器:
const foo = (bar) => {
console.log("here");
return {
type: "FOO",
bar
}
}
在容器的 render() 内部
console.log(1);
console.log(this.props.dispatch);
console.log(foo);
this.props.dispatch(foo(
{a: 1, b: 2}
));
console.log(2);
我在 Chrome 中看到的输出是:
1
<dispatch function>
<my foo reducer function>
here
请注意缺少 2
。
我没有收到任何错误,没有重定向,什么也没有。代码执行在 dispatch()
调用后停止。
任何关于我如何调试它的建议或想法可能是什么问题?
备案:)
您不能在 render()
中调用 dispatch()
。
(因为如果你这样做,你的道具会更新,所以在当前的中间需要一个新的渲染。这将是挂起(等待你自己)或无限递归。证据说挂断电话!)
我有一些代码如下所示:
减速器:
const foo = (bar) => {
console.log("here");
return {
type: "FOO",
bar
}
}
在容器的 render() 内部
console.log(1);
console.log(this.props.dispatch);
console.log(foo);
this.props.dispatch(foo(
{a: 1, b: 2}
));
console.log(2);
我在 Chrome 中看到的输出是:
1
<dispatch function>
<my foo reducer function>
here
请注意缺少 2
。
我没有收到任何错误,没有重定向,什么也没有。代码执行在 dispatch()
调用后停止。
任何关于我如何调试它的建议或想法可能是什么问题?
备案:)
您不能在 render()
中调用 dispatch()
。
(因为如果你这样做,你的道具会更新,所以在当前的中间需要一个新的渲染。这将是挂起(等待你自己)或无限递归。证据说挂断电话!)