Flux Dispatch.dispatch(…): Cannot dispatch in the middle of a dispatch

忘是亡心i 2022-05-30 03:09 390阅读 0赞

在使用flux进行数据交互的时候,出现了一个问题Flux Dispatch.dispatch(…): Cannot dispatch in the middle of a dispatch,在国内竟然没有找到解决方案,最后在https://stackoverflow.com上找到了解决方案,但是原理不清楚【这不是我的风格,空下来一定搞懂】。

解决方案:

老外是这么说的:
You can make it work by “scheduling” the next action instead of calling it directly, here is an example code:
译:你可以在指定的时间调度一个action而不是直接调用它。

  1. // instead of doing this
  2. Dispatcher.dispatch(...);
  3. // go like this
  4. setTimeout(function() {
  5. Dispatcher.dispatch(...);
  6. }, 1);

我的解决方案:

  1. setTimeout(function () {
  2. Actions.synchronizePanekeyToStore(currenPaneKey);
  3. }, 1);

这样就可以了,真心感觉老外很热心。

发表评论

表情:
评论列表 (有 0 条评论,390人围观)

还没有评论,来说两句吧...

相关阅读