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

后端 未结 4 1820
名媛妹妹
名媛妹妹 2020-12-01 10:52

My code https://gist.github.com/ButuzGOL/707d1605f63eef55e4af

So when I get sign-in success callback I want to make redirect,
redirect works through dispatcher t

4条回答
  •  甜味超标
    2020-12-01 11:18

    You can make it work by "scheduling" the next action instead of calling it directly, here is an example code:

    // instead of doing this
    Dispatcher.dispatch(...);
    
    // go like this
    setTimeout(function() {
      Dispatcher.dispatch(...);
    }, 1);
    

    This will cause your next dispatch to be called later out of the current dispatch process, and no error will happen.

    If your dispatch code is on a callback any kind of other async operation that will work as well (for example in a response for an Ajax request).

    I'm using this style to make some forms respond to generic data here and I'm facing no issue, at least the way I'm using it.

提交回复
热议问题