Infinite loop with ngrx/effects

允我心安 提交于 2019-12-06 04:54:57

An Effect allows you watch a given action type and react to that action every time it's been dispatched.

So if you watch actions X in some effect and dispatch from that effect another action X, you'll end up in an infinite loop.

In your case : Your action is of type .ofType(monitor.ActionTypes.INCREMENT) and from your effect you then dispatch an action monitor.ActionTypes.INCREMENT (from this part I assume : monitor.IncrementAction(payload+1)), then the effect is triggered again, and again, and again, ...

I had this same issue, and the answer was that my effect didn't return a completely different action from the one that the current effect was keying on.

For my affect, I only did a .do(), and didn't switchMap it to a new action. That was my issue. Because I didn't need to fire a new action, I made a NoopAction that get returns. It is implying that no one should ever use the NoopAction in a reducer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!