DEV Community

Discussion on: Using request/success/failure pattern in Redux to handle async actions

Collapse
 
aileenr profile image
Aileen Rae

The development team at my work use this pattern across our React apps. We also place all the action type variables in one file then import where needed. That way any developer looking at a project for the first time can see all API interactions in the app at a glance.

Collapse
 
zhnedyalkow profile image
Zhitomir Oreshenski

Hi,

You can try to start implementing redux toolkit and redux thunk. It will simplify the aforementioned boiler plate code.

Collapse
 
sunil12738 profile image
Sunil Chaudhary

Hi Zhitomir,
Thanks for your valuable inputs.
Our team doesn't use this code directly. We have a lot of utility functions (inspired by redux-toolkit and redux-actions) which reduce this repetitive boilerplate code to zero. You can read the article published over here

Thread Thread
 
zhnedyalkow profile image
Zhitomir Oreshenski

Hi, thank you for your response.

Well, I have already used it in some of our projects, just shared my personal experience and this is one of the trends right now. I can verify that aforementioned pattern is easy to implement but of'course there are always alternatives. We try as much as possible to encapsulate each slice of the state in separate modul with all interfaces.

Collapse
 
sunil12738 profile image
Sunil Chaudhary

Hi Aileen,
Yes this is a very good approach. However, there is a lot of boilerplate code involved. I hope your team uses some libraries or utilities to avoid the boilerplate code. I have also published Part 2 of the article which shows a way to simplify the code a lot. You can read it here