Is it possible to fire two types of action at Redux at the same time?

Asked

Viewed 121 times

0

I’m using Redux and Redux-saga in an application with React and with doubt when it comes to displaying the load to the user when a saga is launched. I don’t know if this is good practice, but I was thinking about the possibility of shooting 2 actions. 1 for load display and another to trigger the saga. It is possible to fire two types of action at the same time?

1 answer

1

Speaking of Redux, no matter how hard you try, you’ll only be able to fire one action at a time, because in , the instructions are executed one at a time and even if you use Redux-Saga, Redux-Thunk or whatever, to treat asynchronous actions, will remain one. But this does not mean that they will be resolved in the order they are executed.

In your case, it is quite valid to approach an action before p/ update the loading state, a second action p/ do a fetch or other asynchronous operation and a third p/ change the loading status again.

When it comes to saga, I have no idea why I never used it. But the principle is the same.

  • Thanks @jan, after searching I found that within the saga I can fire an action for the load and after the return of the ajax I can fire another to hide the load.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.