It is generally advised to move your async stuff to redux-middleware:
- to make your components are "just" a view layer.
- this also makes your components "cleaner" and easier to test.
- you can avoid incidentally introducing bugs like memory leaks. For example:
- if a Promise has
setState
in a then
function then it is not guaranteed that component will still be mounted when Promise resolves.
- the same with
setTimeout
or setInterval
- someone may forget to unsubscribe from them when component unmounts and react will throw error.
- people often get confused how to properly use react lifecycle (that's why react deprecated
componentWillMount
, componentWillUpdate
and componentWillReceiveProps
).
- Libraries like
redux-saga
or redux-observable
make such async task easy to accomplish.
However... if you have a very simple situation then moving your code trough middleware may add unnecessary complexity. So, in the end, it's best to do what will be easier to understand and handle in future.