DEV Community

Ola' John Ajiboye
Ola' John Ajiboye

Posted on

Why thunk,sagas and so many middlewares for Redux?

Why do we have to use thunk sagas etc to hanlde async state chnages in React. Was it an after tought to Redux. VueX seems to handles these things well without additional middlewares.

Top comments (3)

Collapse
 
vonheikemen profile image
Heiker • Edited

That's because Redux has a very simple implementation, and it is actually unaware of React, you have to bring react-redux for them to work together. Middlewares are necessary to add features that Redux doesn't have out the box. Actions in Redux are merely a convention, it is the recomended way of doing thing but are not necesary, the same goes for the switch statement in a reducer.

Vuex on the other hand is more complex in its implementation and it was made specifically to work with Vue. Actions are an integral part of Vuex and already provide you with features that you could find in redux-thunk.

Collapse
 
mongopark profile image
Ola' John Ajiboye

True. That kind of makes sense. I forgot that Redux isn't intended just for React. Do you think context API helps in this case since it's React specific.

Thanks.

Collapse
 
vonheikemen profile image
Heiker

Yes, it does help. React has added features in the core library that now help with state management and side effects. If you want to know more this article is a good start: Application State Management with React.