A
A
aleks_web_dev2020-11-03 23:14:45
React
aleks_web_dev, 2020-11-03 23:14:45

When to make asynchronous requests?

I’m writing in react and redux and just now I’m thinking why should I use middleware if you can just make an asynchronous request to componentDidMount and then dispatch it like a normal actioncreator ?
And you can call any other function and then how will it return the answer already dispatch the data?
why then use redux-thunk redux-saga

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
krundetz, 2020-11-04
@krundetz

1. Because hooks in React appeared in version 16.8, and redux-thunk, redux-saga earlier and those who already use them will have to rewrite the working code.
2. The approaches themselves are still different. And if one approach works for you and works well, why would the other be better?

A
Arthur, 2020-11-04
@cloudz

redux-thunk and redux-saga are designed to conveniently support transactions when, for example, it is necessary to process a chain of asynchronous requests, + this is all taken out in a separate layer of logic, allowing you to concentrate on it in one place, and on ui in another

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question