Home > Software engineering >  Angular NgRx state update synchronously
Angular NgRx state update synchronously

Time:09-27

I have NgRx-Effects in place and related action to fetch data from the service and that updates my initial state let's say 'schoolData'is the state property name, which works very well.

Now, I have some event on the form from which I want to update the same state as aforesaid where in I will transform the data and will update the state.

I am aware of the asynchronous way of managing state, but In my case can the effect be used for updating state synchronously?

snippet from NgRx.io: says it can have that as well.

Effects perform tasks, which are synchronous or asynchronous and return a new action.

Can anyone has a working example of this or can lead me into the right direction?

CodePudding user response:

The effect logic itself is called synchronously. When you trigger an async call inside of it, like fetching data, it "becomes" async.

But: Effects are made for isolating "side effects" like async calls. When you don't have to do any impure side effects that you want to isolate, I would rather place this state update logic inside a reducer.

  • Related